Просмотр исходного кода

ncd: small memory optimization

ambrop7 13 лет назад
Родитель
Сommit
c59047d273
4 измененных файлов с 15 добавлено и 6 удалено
  1. 10 1
      ncd/NCDInterpBlock.c
  2. 3 1
      ncd/NCDInterpBlock.h
  3. 1 1
      ncd/NCDInterpProg.c
  4. 1 3
      ncd/ncd.c

+ 10 - 1
ncd/NCDInterpBlock.c

@@ -68,7 +68,7 @@ static int compute_prealloc (NCDInterpBlock *o)
     return 1;
 }
 
-int NCDInterpBlock_Init (NCDInterpBlock *o, NCDBlock *block)
+int NCDInterpBlock_Init (NCDInterpBlock *o, NCDBlock *block, NCDProcess *process)
 {
     if (NCDBlock_NumStatements(block) > INT_MAX) {
         BLog(BLOG_ERROR, "too many statements");
@@ -124,6 +124,8 @@ int NCDInterpBlock_Init (NCDInterpBlock *o, NCDBlock *block)
     
     ASSERT(o->num_stmts == num_stmts)
     
+    o->process = process;
+    
     DebugObject_Init(&o->d_obj);
     return 1;
     
@@ -255,3 +257,10 @@ int NCDInterpBlock_StatementPreallocOffset (NCDInterpBlock *o, int i)
     
     return o->stmts[i].prealloc_offset;
 }
+
+NCDProcess * NCDInterpBlock_Process (NCDInterpBlock *o)
+{
+    DebugObject_Access(&o->d_obj);
+    
+    return o->process;
+}

+ 3 - 1
ncd/NCDInterpBlock.h

@@ -58,10 +58,11 @@ typedef struct {
     int num_stmts;
     int prealloc_size;
     NCDInterpBlock__Hash hash;
+    NCDProcess *process;
     DebugObject d_obj;
 } NCDInterpBlock;
 
-int NCDInterpBlock_Init (NCDInterpBlock *o, NCDBlock *block) WARN_UNUSED;
+int NCDInterpBlock_Init (NCDInterpBlock *o, NCDBlock *block, NCDProcess *process) WARN_UNUSED;
 void NCDInterpBlock_Free (NCDInterpBlock *o);
 int NCDInterpBlock_FindStatement (NCDInterpBlock *o, int from_index, const char *name);
 const char * NCDInterpBlock_StatementCmdName (NCDInterpBlock *o, int i);
@@ -71,5 +72,6 @@ void NCDInterpBlock_StatementBumpAllocSize (NCDInterpBlock *o, int i, int alloc_
 int NCDInterpBlock_StatementPreallocSize (NCDInterpBlock *o, int i);
 int NCDInterpBlock_PreallocSize (NCDInterpBlock *o);
 int NCDInterpBlock_StatementPreallocOffset (NCDInterpBlock *o, int i);
+NCDProcess * NCDInterpBlock_Process (NCDInterpBlock *o);
 
 #endif

+ 1 - 1
ncd/NCDInterpProg.c

@@ -68,7 +68,7 @@ int NCDInterpProg_Init (NCDInterpProg *o, NCDProgram *prog)
         e->name = NCDProcess_Name(p);
         e->proc = p;
         
-        if (!NCDInterpBlock_Init(&e->iblock, NCDProcess_Block(p))) {
+        if (!NCDInterpBlock_Init(&e->iblock, NCDProcess_Block(p), p)) {
             BLog(BLOG_ERROR, "NCDInterpBlock_Init failed");
             goto fail2;
         }

+ 1 - 3
ncd/ncd.c

@@ -85,7 +85,6 @@ struct statement {
 };
 
 struct process {
-    NCDProcess *proc_ast;
     NCDInterpBlock *iblock;
     NCDModuleProcess *module_process;
     BTimer wait_timer;
@@ -651,7 +650,6 @@ static int process_new (NCDProcess *proc_ast, NCDInterpBlock *iblock, NCDModuleP
     }
     
     // set variables
-    p->proc_ast = proc_ast;
     p->iblock = iblock;
     p->module_process = module_process;
     p->statements = v_statements;
@@ -782,7 +780,7 @@ void process_assert_pointers (struct process *p)
 
 void process_logfunc (struct process *p)
 {
-    BLog_Append("process %s: ", NCDProcess_Name(p->proc_ast));
+    BLog_Append("process %s: ", NCDProcess_Name(NCDInterpBlock_Process(p->iblock)));
 }
 
 void process_log (struct process *p, int level, const char *fmt, ...)