summaryrefslogtreecommitdiffstats
path: root/src/bplist.c
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2016-05-12 02:32:55 +0200
committerGravatar Nikias Bassen2016-05-12 02:32:55 +0200
commit2af7318239c59555869d018bc355fe0e21d900c6 (patch)
tree3b366f10c04d305c9bd72e31e28ca62596ba07dd /src/bplist.c
parent6ab7e301f1854fd18891ddfeaa64e7485be990ba (diff)
downloadlibplist-2af7318239c59555869d018bc355fe0e21d900c6.tar.gz
libplist-2af7318239c59555869d018bc355fe0e21d900c6.tar.bz2
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.
Diffstat (limited to 'src/bplist.c')
-rw-r--r--src/bplist.c11
1 files changed, 7 insertions, 4 deletions
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;
}