diff options
author | Gustavo Sverzut Barbieri <barbieri@profusion.mobi> | 2011-12-10 11:44:31 -0200 |
---|---|---|
committer | Gustavo Sverzut Barbieri <barbieri@profusion.mobi> | 2011-12-10 11:44:31 -0200 |
commit | 15c1c143f29b1a74607b0db9ce01431498dcde95 (patch) | |
tree | 1baeabbd45daeaf180997ac604e3c54231acf683 /libkmod | |
parent | fc2d835df5ab75d40eb29d79fbcf16948860bb5a (diff) | |
download | kmod-15c1c143f29b1a74607b0db9ce01431498dcde95.tar.gz |
index-mm: no need to allocate prefix.
Diffstat (limited to 'libkmod')
-rw-r--r-- | libkmod/libkmod-index.c | 24 |
1 files changed, 9 insertions, 15 deletions
diff --git a/libkmod/libkmod-index.c b/libkmod/libkmod-index.c index f8d6327..d97a03c 100644 --- a/libkmod/libkmod-index.c +++ b/libkmod/libkmod-index.c @@ -534,6 +534,8 @@ struct index_value *index_searchwild(struct index_file *in, const char *key) #include <sys/stat.h> #include <unistd.h> +static const char _idx_empty_str[] = ""; + /**************************************************************************/ /* * Alternative implementation, using mmap to map all the file to memory when @@ -548,7 +550,7 @@ struct index_mm { struct index_mm_node { struct index_mm *idx; - char *prefix; + const char *prefix; /* mmape'd value */ struct index_value *values; unsigned char first; unsigned char last; @@ -575,14 +577,6 @@ static inline uint8_t read_char_mm(void **p) return v; } -static inline char *read_alloc_chars_mm(void **p) -{ - char *addr = *(char **)p; - size_t len = strlen(addr) + 1; - *p = addr + len; - return memdup(addr, len); -} - static inline char *read_chars_mm(void **p, unsigned *rlen) { char *addr = *(char **)p; @@ -595,7 +589,7 @@ static struct index_mm_node *index_mm_read_node(struct index_mm *idx, uint32_t offset) { void *p = idx->mm; struct index_mm_node *node; - char *prefix; + const char *prefix; int i, child_count = 0; @@ -604,10 +598,11 @@ static struct index_mm_node *index_mm_read_node(struct index_mm *idx, p = (char *)p + (offset & INDEX_NODE_MASK); - if (offset & INDEX_NODE_PREFIX) - prefix = read_alloc_chars_mm(&p); - else - prefix = strdup(""); + if (offset & INDEX_NODE_PREFIX) { + unsigned len; + prefix = read_chars_mm(&p, &len); + } else + prefix = _idx_empty_str; if (offset & INDEX_NODE_CHILDS) { char first = read_char_mm(&p); @@ -651,7 +646,6 @@ static struct index_mm_node *index_mm_read_node(struct index_mm *idx, static void index_mm_free_node(struct index_mm_node *node) { - free(node->prefix); index_values_free(node->values); free(node); } |