summaryrefslogtreecommitdiff
path: root/hashmap.h
diff options
context:
space:
mode:
authorKarsten Blees <karsten.blees@gmail.com>2014-07-02 22:22:54 (GMT)
committerJunio C Hamano <gitster@pobox.com>2014-07-07 20:56:38 (GMT)
commit7b64d42d22206d9995a8f0cb3b515e623cac4702 (patch)
tree26895c5fde113b1d84f52409f951feb37f451412 /hashmap.h
parentab73a9d119240b0b908ccb9edd19b8e536ce29b9 (diff)
downloadgit-7b64d42d22206d9995a8f0cb3b515e623cac4702.zip
git-7b64d42d22206d9995a8f0cb3b515e623cac4702.tar.gz
git-7b64d42d22206d9995a8f0cb3b515e623cac4702.tar.bz2
hashmap: add string interning API
Interning short strings with high probability of duplicates can reduce the memory footprint and speed up comparisons. Add strintern() and memintern() APIs that use a hashmap to manage the pool of unique, interned strings. Note: strintern(getenv()) could be used to sanitize git's use of getenv(), in case we ever encounter a platform where a call to getenv() invalidates previous getenv() results (which is allowed by POSIX). Signed-off-by: Karsten Blees <blees@dcon.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'hashmap.h')
-rw-r--r--hashmap.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/hashmap.h b/hashmap.h
index a8b9e3d..ab7958a 100644
--- a/hashmap.h
+++ b/hashmap.h
@@ -87,4 +87,12 @@ static inline void *hashmap_iter_first(struct hashmap *map,
return hashmap_iter_next(iter);
}
+/* string interning */
+
+extern const void *memintern(const void *data, size_t len);
+static inline const char *strintern(const char *string)
+{
+ return memintern(string, strlen(string));
+}
+
#endif