Kaynağa Gözat

ncd: small optimization

ambrop7 13 yıl önce
ebeveyn
işleme
7e22cd7a6b
5 değiştirilmiş dosya ile 10 ekleme ve 8 silme
  1. 2 2
      ncd/NCDInterpBlock.c
  2. 1 1
      ncd/NCDInterpBlock.h
  3. 3 3
      ncd/NCDVal.c
  4. 3 1
      ncd/NCDVal.h
  5. 1 1
      ncd/ncd.c

+ 2 - 2
ncd/NCDInterpBlock.c

@@ -307,7 +307,7 @@ char ** NCDInterpBlock_StatementObjNames (NCDInterpBlock *o, int i)
     return o->stmts[i].objnames;
 }
 
-int NCDInterpBlock_CopyStatementArgs (NCDInterpBlock *o, int i, NCDValMem *out_valmem, NCDValRef *out_val, NCDValReplaceProg **out_prog)
+int NCDInterpBlock_CopyStatementArgs (NCDInterpBlock *o, int i, NCDValMem *out_valmem, NCDValRef *out_val, NCDValReplaceProg *out_prog)
 {
     DebugObject_Access(&o->d_obj);
     ASSERT(i >= 0)
@@ -323,7 +323,7 @@ int NCDInterpBlock_CopyStatementArgs (NCDInterpBlock *o, int i, NCDValMem *out_v
     }
     
     *out_val = NCDVal_FromSafe(out_valmem, e->arg_ref);
-    *out_prog = &e->arg_prog;
+    *out_prog = e->arg_prog;
     return 1;
 }
 

+ 1 - 1
ncd/NCDInterpBlock.h

@@ -73,7 +73,7 @@ void NCDInterpBlock_Free (NCDInterpBlock *o);
 int NCDInterpBlock_FindStatement (NCDInterpBlock *o, int from_index, const char *name);
 const char * NCDInterpBlock_StatementCmdName (NCDInterpBlock *o, int i);
 char ** NCDInterpBlock_StatementObjNames (NCDInterpBlock *o, int i);
-int NCDInterpBlock_CopyStatementArgs (NCDInterpBlock *o, int i, NCDValMem *out_valmem, NCDValRef *out_val, NCDValReplaceProg **out_prog) WARN_UNUSED;
+int NCDInterpBlock_CopyStatementArgs (NCDInterpBlock *o, int i, NCDValMem *out_valmem, NCDValRef *out_val, NCDValReplaceProg *out_prog) WARN_UNUSED;
 void NCDInterpBlock_StatementBumpAllocSize (NCDInterpBlock *o, int i, int alloc_size);
 int NCDInterpBlock_StatementPreallocSize (NCDInterpBlock *o, int i);
 int NCDInterpBlock_PreallocSize (NCDInterpBlock *o);

+ 3 - 3
ncd/NCDVal.c

@@ -1034,13 +1034,13 @@ void NCDValReplaceProg_Free (NCDValReplaceProg *o)
     BFree(o->instrs);
 }
 
-int NCDValReplaceProg_Execute (NCDValReplaceProg *o, NCDValMem *mem, NCDVal_replace_func replace, void *arg)
+int NCDValReplaceProg_Execute (NCDValReplaceProg prog, NCDValMem *mem, NCDVal_replace_func replace, void *arg)
 {
     NCDVal__AssertMem(mem);
     ASSERT(replace)
     
-    for (size_t i = 0; i < o->num_instrs; i++) {
-        struct NCDVal__instr instr = o->instrs[i];
+    for (size_t i = 0; i < prog.num_instrs; i++) {
+        struct NCDVal__instr instr = prog.instrs[i];
         
         if (instr.type == NCDVAL_INSTR_PLACEHOLDER) {
 #ifndef NDEBUG

+ 3 - 1
ncd/NCDVal.h

@@ -540,7 +540,9 @@ typedef int (*NCDVal_replace_func) (void *arg, int plid, NCDValMem *mem, NCDValR
  * Returns 1 on success and 0 on failure. On failure, the entire memory object enters
  * and inconsistent state and must be freed using {@link NCDValMem_Free} before
  * performing any other operation on it.
+ * The program is passed by value instead of pointer because this appears to be faster.
+ * Is is not modified in any way.
  */
-int NCDValReplaceProg_Execute (NCDValReplaceProg *o, NCDValMem *mem, NCDVal_replace_func replace, void *arg);
+int NCDValReplaceProg_Execute (NCDValReplaceProg prog, NCDValMem *mem, NCDVal_replace_func replace, void *arg);
 
 #endif

+ 1 - 1
ncd/ncd.c

@@ -1042,7 +1042,7 @@ void process_advance (struct process *p)
     
     // copy arguments
     NCDValRef args;
-    NCDValReplaceProg *prog;
+    NCDValReplaceProg prog;
     if (!NCDInterpBlock_CopyStatementArgs(p->iblock, ps->i, &ps->args_mem, &args, &prog)) {
         statement_log(ps, BLOG_ERROR, "NCDInterpBlock_CopyStatementArgs failed");
         goto fail0;