From 2af7318239c59555869d018bc355fe0e21d900c6 Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Thu, 12 May 2016 02:32:55 +0200 Subject: bplist: Speed up plist_to_bin conversion for large plists Using a better hashing algorithm and a larger hash table the conversion is A LOT faster when processing large plists. Thanks to Xiao Deng for reporting this issue and suggesting a fix. --- src/bplist.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/bplist.c') diff --git a/src/bplist.c b/src/bplist.c index 3ba46a2..bb73b31 100644 --- a/src/bplist.c +++ b/src/bplist.c @@ -735,7 +735,7 @@ static unsigned int plist_data_hash(const void* key) case PLIST_KEY: case PLIST_STRING: buff = data->strval; - size = strlen(buff); + size = data->length; break; case PLIST_DATA: case PLIST_ARRAY: @@ -752,9 +752,12 @@ static unsigned int plist_data_hash(const void* key) break; } - //now perform hash - for (i = 0; i < size; buff++, i++) - hash = hash << 7 ^ (*buff); + // now perform hash using djb2 hashing algorithm + // see: http://www.cse.yorku.ca/~oz/hash.html + hash += 5381; + for (i = 0; i < size; buff++, i++) { + hash = ((hash << 5) + hash) + *buff; + } return hash; } -- cgit v1.1-32-gdbae