Commit 21dfa79e authored by Michael Tremer's avatar Michael Tremer

stringpool: Drop function to find next offset

Signed-off-by: default avatarMichael Tremer <michael.tremer@ipfire.org>
parent c8603967
...@@ -255,14 +255,6 @@ struct loc_stringpool* loc_stringpool_unref(struct loc_stringpool* pool) { ...@@ -255,14 +255,6 @@ struct loc_stringpool* loc_stringpool_unref(struct loc_stringpool* pool) {
return NULL; return NULL;
} }
static off_t loc_stringpool_get_next_offset(struct loc_stringpool* pool, off_t offset) {
const char* string = loc_stringpool_get(pool, offset);
if (!string)
return offset;
return offset + strlen(string) + 1;
}
const char* loc_stringpool_get(struct loc_stringpool* pool, off_t offset) { const char* loc_stringpool_get(struct loc_stringpool* pool, off_t offset) {
return __loc_stringpool_get(pool, offset); return __loc_stringpool_get(pool, offset);
} }
...@@ -280,14 +272,17 @@ static off_t loc_stringpool_find(struct loc_stringpool* pool, const char* s) { ...@@ -280,14 +272,17 @@ static off_t loc_stringpool_find(struct loc_stringpool* pool, const char* s) {
off_t offset = 0; off_t offset = 0;
while (offset < pool->length) { while (offset < pool->length) {
const char* string = loc_stringpool_get(pool, offset); const char* string = loc_stringpool_get(pool, offset);
// Error!
if (!string) if (!string)
break; return 1;
int r = strcmp(s, string); // Is this a match?
if (r == 0) if (strcmp(s, string) == 0)
return offset; return offset;
offset = loc_stringpool_get_next_offset(pool, offset); // Shift offset
offset += strlen(string) + 1;
} }
// Nothing found // Nothing found
...@@ -311,11 +306,12 @@ void loc_stringpool_dump(struct loc_stringpool* pool) { ...@@ -311,11 +306,12 @@ void loc_stringpool_dump(struct loc_stringpool* pool) {
while (offset < pool->length) { while (offset < pool->length) {
const char* string = loc_stringpool_get(pool, offset); const char* string = loc_stringpool_get(pool, offset);
if (!string) if (!string)
break; return;
printf("%jd (%zu): %s\n", (intmax_t)offset, strlen(string), string); printf("%jd (%zu): %s\n", (intmax_t)offset, strlen(string), string);
offset = loc_stringpool_get_next_offset(pool, offset); // Shift offset
offset += strlen(string) + 1;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment