diff options
author | David Robillard <d@drobilla.net> | 2014-09-23 04:33:24 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2014-09-23 04:33:24 +0000 |
commit | 21382932fd8df75884c3e21917d9dbd4527d78ac (patch) | |
tree | 9a780b46a46d5b7fe5ff004b1cca36e8cfae771e /src/zix/hash.c | |
parent | 318c36808bd17f3f84f480ec8b506747f5c316c4 (diff) | |
download | sord-21382932fd8df75884c3e21917d9dbd4527d78ac.tar.gz sord-21382932fd8df75884c3e21917d9dbd4527d78ac.tar.bz2 sord-21382932fd8df75884c3e21917d9dbd4527d78ac.zip |
Reduce memory usage and increase performance with a better data structure.
git-svn-id: http://svn.drobilla.net/sord/trunk@307 3d64ff67-21c5-427c-a301-fe4f08042e5a
Diffstat (limited to 'src/zix/hash.c')
-rw-r--r-- | src/zix/hash.c | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/src/zix/hash.c b/src/zix/hash.c index 655c5df..f633e16 100644 --- a/src/zix/hash.c +++ b/src/zix/hash.c @@ -1,5 +1,5 @@ /* - Copyright 2011 David Robillard <http://drobilla.net> + Copyright 2011-2014 David Robillard <http://drobilla.net> Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -58,13 +58,18 @@ zix_hash_new(ZixHashFunc hash_func, size_t value_size) { ZixHash* hash = (ZixHash*)malloc(sizeof(ZixHash)); - hash->hash_func = hash_func; - hash->equal_func = equal_func; - hash->n_buckets = &sizes[0]; - hash->value_size = value_size; - hash->count = 0; - hash->buckets = (ZixHashEntry**)calloc(*hash->n_buckets, - sizeof(ZixHashEntry*)); + if (hash) { + hash->hash_func = hash_func; + hash->equal_func = equal_func; + hash->n_buckets = &sizes[0]; + hash->value_size = value_size; + hash->count = 0; + if (!(hash->buckets = (ZixHashEntry**)calloc(*hash->n_buckets, + sizeof(ZixHashEntry*)))) { + free(hash); + return NULL; + } + } return hash; } @@ -225,4 +230,3 @@ zix_hash_foreach(ZixHash* hash, } } } - |