diff --git a/src/apk_atom.h b/src/apk_atom.h index 1b6ad6c9670a42eff2d1a30d88439f98de4e0108..2815c53bacfedc6bf07a813f51f468d08a7dc12a 100644 --- a/src/apk_atom.h +++ b/src/apk_atom.h @@ -12,10 +12,12 @@ #include "apk_hash.h" #include "apk_blob.h" +#include "apk_balloc.h" extern apk_blob_t apk_atom_null; struct apk_atom_pool { + struct apk_balloc ba; struct apk_hash hash; }; diff --git a/src/atom.c b/src/atom.c index e2ff83ea4b0102851bb4e34b83038a71d3b7f81a..9742c1e670fabb529bf6a1fbd01cd861273c5cca 100644 --- a/src/atom.c +++ b/src/atom.c @@ -26,17 +26,18 @@ static struct apk_hash_ops atom_ops = { .get_key = atom_hash_get_key, .hash_key = apk_blob_hash, .compare = apk_blob_compare, - .delete_item = (apk_hash_delete_f) free, }; void apk_atom_init(struct apk_atom_pool *atoms) { + apk_balloc_init(&atoms->ba, 64*1024); apk_hash_init(&atoms->hash, &atom_ops, 10000); } void apk_atom_free(struct apk_atom_pool *atoms) { apk_hash_free(&atoms->hash); + apk_balloc_destroy(&atoms->ba); } apk_blob_t *apk_atom_get(struct apk_atom_pool *atoms, apk_blob_t blob, int duplicate) @@ -51,12 +52,12 @@ apk_blob_t *apk_atom_get(struct apk_atom_pool *atoms, apk_blob_t blob, int dupli if (duplicate) { char *ptr; - atom = malloc(sizeof(*atom) + blob.len); + atom = apk_balloc_new_extra(&atoms->ba, struct apk_atom_hashnode, blob.len); ptr = (char*) (atom + 1); memcpy(ptr, blob.ptr, blob.len); atom->blob = APK_BLOB_PTR_LEN(ptr, blob.len); } else { - atom = malloc(sizeof(*atom)); + atom = apk_balloc_new(&atoms->ba, struct apk_atom_hashnode); atom->blob = blob; } apk_hash_insert_hashed(&atoms->hash, atom, hash);