diff options
author | Michal Krol <[email protected]> | 2009-06-21 17:03:15 +0200 |
---|---|---|
committer | Michal Krol <[email protected]> | 2009-09-07 10:11:46 +0200 |
commit | 5e8e3cddae9b2797cfa525c643c701debe2f4c04 (patch) | |
tree | 8eeb6a4d1a2e72251d483620c73c5f2cc6b5d5b6 /src/glsl/pp/sl_pp_context.c | |
parent | fd991d845a5f639b9b675a4840ad234c151d56b4 (diff) |
glsl: Rename sl_pp_context_add_str to sl_pp_context_add_unique_str.
Return the same offset for same strings. Allows to compare strings
by comparing their's offsets.
Diffstat (limited to 'src/glsl/pp/sl_pp_context.c')
-rw-r--r-- | src/glsl/pp/sl_pp_context.c | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/glsl/pp/sl_pp_context.c b/src/glsl/pp/sl_pp_context.c index 8722376ae52..6d3076b8697 100644 --- a/src/glsl/pp/sl_pp_context.c +++ b/src/glsl/pp/sl_pp_context.c @@ -43,14 +43,28 @@ sl_pp_context_destroy(struct sl_pp_context *context) } int -sl_pp_context_add_str(struct sl_pp_context *context, - const char *str) +sl_pp_context_add_unique_str(struct sl_pp_context *context, + const char *str) { unsigned int size; - unsigned int offset; + unsigned int offset = 0; size = strlen(str) + 1; + /* Find out if this is a unique string. */ + while (offset < context->cstr_pool_len) { + const char *str2; + unsigned int size2; + + str2 = &context->cstr_pool[offset]; + size2 = strlen(str2) + 1; + if (size == size2 && !memcmp(str, str2, size - 1)) { + return offset; + } + + offset += size2; + } + if (context->cstr_pool_len + size > context->cstr_pool_max) { context->cstr_pool_max = (context->cstr_pool_len + size + 0xffff) & ~0xffff; context->cstr_pool = realloc(context->cstr_pool, context->cstr_pool_max); |