From 487d79f40167a9599f2ddaedd5fdf285031b9e9e Mon Sep 17 00:00:00 2001 From: David Barr Date: Tue, 25 May 2010 20:31:50 +1000 Subject: [PATCH] Add pool_tok_seq() to string_pool.c To reduce the amount of allocations that need to occur, provide a method to tokenise paths when first encountered. The token lists can be used in place of strings. There are wide-reaching API implications for this change. Signed-off-by: David Barr --- string_pool.c | 12 ++++++++++++ string_pool.h | 1 + 2 files changed, 13 insertions(+) diff --git a/string_pool.c b/string_pool.c index 4624134..cffb9ce 100644 --- a/string_pool.c +++ b/string_pool.c @@ -77,6 +77,18 @@ void pool_print_seq(uint32_t len, uint32_t *seq, char delim, FILE *stream) } } +uint32_t pool_tok_seq(uint32_t max, uint32_t *seq, char *delim, char *str) +{ + char *context; + uint32_t length, token; + for (length = 0, token = pool_tok_r(str, delim, &context); + length < max && ~token; + length++, token = pool_tok_r(NULL, delim, &context)) { + seq[length] = token; + } + return length; +} + void pool_reset(void) { node_reset(); diff --git a/string_pool.h b/string_pool.h index fb9e6b8..870e25c 100644 --- a/string_pool.h +++ b/string_pool.h @@ -6,6 +6,7 @@ uint32_t pool_tok_r(char *str, const char *delim, char **saveptr); void pool_print_seq(uint32_t len, uint32_t *seq, char delim, FILE *stream); +uint32_t pool_tok_seq(uint32_t max, uint32_t *seq, char *delim, char *str); void pool_reset(void); #endif -- 2.11.4.GIT