Skip to content
Snippets Groups Projects
Commit 8bd34603 authored by Timo Teräs's avatar Timo Teräs
Browse files

atom: use bump allocator

parent aef59817
No related branches found
No related tags found
No related merge requests found
......@@ -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;
};
......
......@@ -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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment