]> Nishi Git Mirror - gwion.git/commitdiff
:art: Improve vararg mem usage
authorJérémie Astor <fennecdjay@gmail.com>
Fri, 23 Jul 2021 10:52:51 +0000 (12:52 +0200)
committerJérémie Astor <fennecdjay@gmail.com>
Fri, 23 Jul 2021 10:52:51 +0000 (12:52 +0200)
src/emit/emit.c
src/lib/vararg.c

index 274dac81f3402e81a27d7d08efff5c669da37826..0ef37ff678e0bda58d2f2e044128ecc0913fe5c0 100644 (file)
@@ -1006,11 +1006,12 @@ ANN static m_uint vararg_size(const Gwion gwion, const Exp_Call *exp_call,
 ANN static void emit_func_arg_vararg(const Emitter   emit,
                                      const Exp_Call *exp_call) {
   const Instr  instr = emit_add_instr(emit, VarargIni);
-  const Vector kinds = new_vector(emit->gwion->mp);
-  if ((instr->m_val = vararg_size(emit->gwion, exp_call, kinds)))
-    instr->m_val2 = (m_uint)kinds;
+  struct Vector_ kinds;
+  vector_init(&kinds);
+  if ((instr->m_val = vararg_size(emit->gwion, exp_call, &kinds)))
+    instr->m_val2 = (m_uint)kinds.ptr;
   else
-    free_vector(emit->gwion->mp, kinds);
+    vector_release(&kinds);
 }
 
 ANN static m_bool emit_func_args(const Emitter emit, const Exp_Call *exp_call) {
index 0bed62041c6c8aef786772bc1a2a9b7ebd692723..8ab6c14e255c0baeed0feb5582805f2cd3e00abf 100644 (file)
@@ -70,7 +70,7 @@ INSTR(VarargIni) {
   POP_REG(shred, instr->m_val - SZ_INT)
   if ((*(m_uint *)(o->data + SZ_INT * 2) = instr->m_val)) {
     arg->d             = (m_bit *)xmalloc(round2szint(instr->m_val));
-    const Vector kinds = (Vector)instr->m_val2;
+    const Vector kinds = (Vector)&instr->m_val2;
     vector_copy2(kinds, &arg->t);
     m_uint offset = 0;
     for (m_uint i = 0; i < vector_size(&arg->t); ++i) {
@@ -137,7 +137,7 @@ static OP_EMIT(opem_vararg_cast) {
 }
 
 static FREEARG(freearg_vararg) {
-  if (instr->m_val2) free_vector(((Gwion)gwion)->mp, (Vector)instr->m_val2);
+  if (instr->m_val2) vector_release((Vector)&instr->m_val2);
 }
 
 static ID_CHECK(idck_vararg) {