Mesa (glsl-pp-rework-1): glsl: Rename sl_pp_context_add_str to sl_pp_context_add_unique_str.
MichaŠKról
michal at kemper.freedesktop.org
Fri Jun 26 10:54:18 UTC 2009
Module: Mesa
Branch: glsl-pp-rework-1
Commit: 72bd8e8617d3b15fc410e78ea5195a4d0e0b4d2c
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=72bd8e8617d3b15fc410e78ea5195a4d0e0b4d2c
Author: Michal Krol <michal at vmware.com>
Date: Sun Jun 21 17:03:15 2009 +0200
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.
---
src/glsl/pp/sl_pp_context.c | 20 +++++++++++++++++---
src/glsl/pp/sl_pp_context.h | 4 ++--
src/glsl/pp/sl_pp_token.c | 4 ++--
src/glsl/pp/sl_pp_token.h | 2 ++
4 files changed, 23 insertions(+), 7 deletions(-)
diff --git a/src/glsl/pp/sl_pp_context.c b/src/glsl/pp/sl_pp_context.c
index 8722376..6d3076b 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);
diff --git a/src/glsl/pp/sl_pp_context.h b/src/glsl/pp/sl_pp_context.h
index cb81f73..56f7077 100644
--- a/src/glsl/pp/sl_pp_context.h
+++ b/src/glsl/pp/sl_pp_context.h
@@ -46,8 +46,8 @@ void
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);
const char *
sl_pp_context_cstr(const struct sl_pp_context *context,
diff --git a/src/glsl/pp/sl_pp_token.c b/src/glsl/pp/sl_pp_token.c
index e200b96..68c8fbe 100644
--- a/src/glsl/pp/sl_pp_token.c
+++ b/src/glsl/pp/sl_pp_token.c
@@ -53,7 +53,7 @@ _tokenise_identifier(struct sl_pp_context *context,
}
identifier[i++] = '\0';
- info->data.identifier = sl_pp_context_add_str(context, identifier);
+ info->data.identifier = sl_pp_context_add_unique_str(context, identifier);
if (info->data.identifier == -1) {
return -1;
}
@@ -91,7 +91,7 @@ _tokenise_number(struct sl_pp_context *context,
}
number[i++] = '\0';
- info->data.number = sl_pp_context_add_str(context, number);
+ info->data.number = sl_pp_context_add_unique_str(context, number);
if (info->data.number == -1) {
return -1;
}
diff --git a/src/glsl/pp/sl_pp_token.h b/src/glsl/pp/sl_pp_token.h
index c801804..a53720b 100644
--- a/src/glsl/pp/sl_pp_token.h
+++ b/src/glsl/pp/sl_pp_token.h
@@ -28,6 +28,8 @@
#ifndef SL_PP_TOKEN_H
#define SL_PP_TOKEN_H
+#include "sl_pp_context.h"
+
enum sl_pp_token {
SL_PP_WHITESPACE,
More information about the mesa-commit
mailing list