]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
code_cachedstring
authorWolfgang Bumiller <wolfgang.linux@bumiller.com>
Fri, 4 May 2012 22:28:30 +0000 (00:28 +0200)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Wed, 9 May 2012 13:03:19 +0000 (15:03 +0200)
code.c
gmqcc.h

diff --git a/code.c b/code.c
index b3cc0b825bb03ec6369eb528102c817d3a4f37e2..438f1dcd31a2cb02bc672da77ae6c49b48338030 100644 (file)
--- a/code.c
+++ b/code.c
@@ -113,6 +113,22 @@ uint32_t code_genstring(const char *str)
     return off;
 }
 
+uint32_t code_cachedstring(const char *str)
+{
+    size_t s = 0;
+    /* We could implement knuth-morris-pratt or something
+     * and also take substrings, but I'm uncomfortable with
+     * pointing to subparts of strings for the sake of clarity...
+     */
+    while (s < code_chars_elements) {
+        if (!strcmp(str, code_chars_data + s))
+            return s;
+        while (code_chars_data[s]) ++s;
+        ++s;
+    }
+    return code_genstring(str);
+}
+
 void code_test() {
     prog_section_def       d1 = { TYPE_VOID,     28, 1 };
     prog_section_def       d2 = { TYPE_FUNCTION, 29, 8 };
diff --git a/gmqcc.h b/gmqcc.h
index 7178c8f3cac0fb69accb3841c9cb763be7880d1f..7290cb61392ac35501be7508e3c5016ce70ba29f 100644 (file)
--- a/gmqcc.h
+++ b/gmqcc.h
@@ -533,9 +533,10 @@ VECTOR_PROT(char,                   code_chars     );
  * code_write -- writes out the compiled file
  * code_init  -- prepares the code file
  */
-bool     code_write     (const char *filename);
-void     code_init      ();
-uint32_t code_genstring (const char *string);
+bool     code_write       (const char *filename);
+void     code_init        ();
+uint32_t code_genstring   (const char *string);
+uint32_t code_cachedstring(const char *string);
 
 /*===================================================================*/
 /*========================= assembler.c =============================*/