]> git.rm.cloudns.org Git - xonotic/gmqcc.git/commitdiff
cache filenames as such instead of using code_cachedstring
authorWolfgang (Blub) Bumiller <blub@speed.at>
Fri, 24 Aug 2012 17:44:29 +0000 (19:44 +0200)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Fri, 24 Aug 2012 17:44:29 +0000 (19:44 +0200)
ir.c
ir.h

diff --git a/ir.c b/ir.c
index 41575a5f3e98ed5bcac1f5ca0ab1b989decbcc78..7af697961edc9902d79b1d95243244e6111fee7d 100644 (file)
--- a/ir.c
+++ b/ir.c
@@ -166,6 +166,8 @@ ir_builder* ir_builder_new(const char *modulename)
     MEM_VECTOR_INIT(self, functions);
     MEM_VECTOR_INIT(self, globals);
     MEM_VECTOR_INIT(self, fields);
+    MEM_VECTOR_INIT(self, filenames);
+    MEM_VECTOR_INIT(self, filestrings);
     self->name = NULL;
     if (!ir_builder_set_name(self, modulename)) {
         mem_d(self);
@@ -175,9 +177,11 @@ ir_builder* ir_builder_new(const char *modulename)
     return self;
 }
 
-MEM_VEC_FUNCTIONS(ir_builder, ir_value*, globals)
-MEM_VEC_FUNCTIONS(ir_builder, ir_value*, fields)
+MEM_VEC_FUNCTIONS(ir_builder, ir_value*,    globals)
+MEM_VEC_FUNCTIONS(ir_builder, ir_value*,    fields)
 MEM_VEC_FUNCTIONS(ir_builder, ir_function*, functions)
+MEM_VEC_FUNCTIONS(ir_builder, const char*,  filenames)
+MEM_VEC_FUNCTIONS(ir_builder, qcint,        filestrings)
 
 void ir_builder_delete(ir_builder* self)
 {
@@ -195,6 +199,8 @@ void ir_builder_delete(ir_builder* self)
         ir_value_delete(self->fields[i]);
     }
     MEM_VECTOR_CLEAR(self, fields);
+    MEM_VECTOR_CLEAR(self, filenames);
+    MEM_VECTOR_CLEAR(self, filestrings);
     mem_d(self);
 }
 
@@ -2549,6 +2555,27 @@ static bool gen_function_code(ir_function *self)
     return true;
 }
 
+static qcint ir_builder_filestring(ir_builder *ir, const char *filename)
+{
+    /* NOTE: filename pointers are copied, we never strdup them,
+     * thus we can use pointer-comparison to find the string.
+     */
+    size_t i;
+    qcint  str;
+
+    for (i = 0; i < ir->filenames_count; ++i) {
+        if (ir->filenames[i] == filename)
+            return ir->filestrings[i];
+    }
+
+    str = code_genstring(filename);
+    if (!ir_builder_filenames_add(ir, filename))
+        return 0;
+    if (!ir_builder_filestrings_add(ir, str))
+        ir->filenames_count--;
+    return str;
+}
+
 static bool gen_global_function(ir_builder *ir, ir_value *global)
 {
     prog_section_function fun;
@@ -2566,7 +2593,7 @@ static bool gen_global_function(ir_builder *ir, ir_value *global)
     irfun = global->constval.vfunc;
 
     fun.name    = global->code.name;
-    fun.file    = code_cachedstring(global->context.file);
+    fun.file    = ir_builder_filestring(ir, global->context.file);
     fun.profile = 0; /* always 0 */
     fun.nargs   = irfun->params_count;
 
diff --git a/ir.h b/ir.h
index 95fdd57520d50ec724e10cc8969175d5dd454bf7..825f6a7123db4893b40f23aacc0532e9feb2eef1 100644 (file)
--- a/ir.h
+++ b/ir.h
@@ -305,6 +305,9 @@ typedef struct ir_builder_s
     MEM_VECTOR_MAKE(ir_function*, functions);
     MEM_VECTOR_MAKE(ir_value*, globals);
     MEM_VECTOR_MAKE(ir_value*, fields);
+
+    MEM_VECTOR_MAKE(const char*, filenames);
+    MEM_VECTOR_MAKE(qcint,       filestrings);
 } ir_builder;
 
 ir_builder* ir_builder_new(const char *modulename);
@@ -313,8 +316,10 @@ void        ir_builder_delete(ir_builder*);
 bool ir_builder_set_name(ir_builder *self, const char *name);
 
 MEM_VECTOR_PROTO(ir_builder, ir_function*, functions);
-MEM_VECTOR_PROTO(ir_builder, ir_value*, globals);
-MEM_VECTOR_PROTO(ir_builder, ir_value*, fields);
+MEM_VECTOR_PROTO(ir_builder, ir_value*,    globals);
+MEM_VECTOR_PROTO(ir_builder, ir_value*,    fields);
+MEM_VECTOR_PROTO(ir_builder, const char*,  filenames);
+MEM_VECTOR_PROTO(ir_builder, qcint,        filestrings);
 
 ir_function* ir_builder_get_function(ir_builder*, const char *fun);
 ir_function* ir_builder_create_function(ir_builder*, const char *name, int outtype);