Fill in some default strings in the cache, so we can always compare by pointer.
authorRyan C. Gordon <icculus@icculus.org>
Tue, 19 Oct 2010 17:48:24 -0400
changeset 923 859fc7151d43
parent 922 9b5879d36f36
child 924 c99418745e1b
Fill in some default strings in the cache, so we can always compare by pointer.
mojoshader_compiler.c
--- a/mojoshader_compiler.c	Tue Oct 19 16:59:03 2010 -0400
+++ b/mojoshader_compiler.c	Tue Oct 19 17:48:24 2010 -0400
@@ -561,6 +561,15 @@
     SymbolMap usertypes;
     SymbolMap variables;
     CompilationUnit *ast;  // Abstract Syntax Tree
+
+    // These are entries allocated in the strcache, so these pointers are
+    //  valid from shortly after we create the cache until we destroy it
+    //  with the rest of the context. This makes it so we can compare common
+    //  strings by pointer without having to hash them every time, so long as
+    //  we're comparing a string pointer we know came from this string cache.
+    const char *str_b;  // "b"
+    const char *str_f;  // "f"
+    const char *str_i;  // "i"
 } Context;
 
 
@@ -2466,6 +2475,11 @@
     create_symbolmap(ctx, &ctx->variables); // !!! FIXME: check for failure.
     ctx->strcache = stringcache_create(m, f, d);  // !!! FIXME: check for failure.
 
+    // fill in some common strings we'll want to use without further hashing.
+    ctx->str_b = stringcache(ctx->strcache, "b");
+    ctx->str_f = stringcache(ctx->strcache, "f");
+    ctx->str_i = stringcache(ctx->strcache, "i");
+
     return ctx;
 } // build_context