}
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);
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,
}
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;
}
}
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;
}