Skip to content

Commit

Permalink
compiler: fix --opt-append
Browse files Browse the repository at this point in the history
  • Loading branch information
mertcandav committed Feb 16, 2024
1 parent 6207c99 commit 9049b1f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
2 changes: 1 addition & 1 deletion api/slice.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ namespace jule
}

// Push item to last without allocation checks.
void __push(const Item &item)
inline void __push(const Item &item)
{
this->_slice[this->_len++] = item;
}
Expand Down
25 changes: 10 additions & 15 deletions src/julec/obj/cxx/expr.jule
Original file line number Diff line number Diff line change
Expand Up @@ -876,17 +876,14 @@ impl ExprCoder {
ret obj
}

fn __append_call_assign(mut self, same_dest: bool, &dest_expr: str,
mut &dest_kind: &TypeKind, mut &s: &SliceExprModel, mut &m: &BuiltinAppendCallExprModel): str {
let mut obj = ""
if !same_dest {
obj += dest_expr
obj += " = jule::alloc_for_append("
obj += self.model(m.dest)
obj += ","
obj += conv::itoa(s.elems.len)
obj += ");"
}
fn __append_call_assign(mut self, &dest_expr: str, mut &dest_kind: &TypeKind,
mut &s: &SliceExprModel, mut &m: &BuiltinAppendCallExprModel): str {
let mut obj = dest_expr
obj += " = jule::alloc_for_append("
obj += self.model(m.dest)
obj += ","
obj += conv::itoa(s.elems.len)
obj += ");"
for (_, mut e) in s.elems {
obj += dest_expr
// Use the "__push" function to skip allocation boundary checking.
Expand All @@ -905,14 +902,12 @@ impl ExprCoder {
let mut s = (&SliceExprModel)(m.elements)
let dest_expr = self.model(dest)
let mut dest_var = (&Var)(dest)
let same_dest = m.dest == dest_var
ret self.__append_call_assign(same_dest, dest_expr, dest_var.kind.kind, s, m), true
ret self.__append_call_assign(dest_expr, dest_var.kind.kind, s, m), true
| &StructSubIdentExprModel:
let mut s = (&SliceExprModel)(m.elements)
let dest_expr = self.model(dest)
let mut dest_field = (&StructSubIdentExprModel)(dest).field
let same_dest = m.dest == dest_field
ret self.__append_call_assign(same_dest, dest_expr, dest_field.kind, s, m), true
ret self.__append_call_assign(dest_expr, dest_field.kind, s, m), true
}
}
ret self.append_call(m), false
Expand Down

0 comments on commit 9049b1f

Please sign in to comment.