From fc6b96707730c54fb7ac4040680d79864169b5e0 Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Mon, 27 Jul 2009 19:38:34 +0000 Subject: Calculate the in-memory size of stylesheets and provide some API to access this. svn path=/trunk/libcss/; revision=8830 --- src/select/hash.c | 29 +++++++++++++++++++++++++++++ src/select/hash.h | 2 ++ 2 files changed, 31 insertions(+) (limited to 'src/select') diff --git a/src/select/hash.c b/src/select/hash.c index 9bcfb15..df6ce4e 100644 --- a/src/select/hash.c +++ b/src/select/hash.c @@ -25,6 +25,8 @@ struct css_selector_hash { lwc_context *ctx; + size_t hash_size; + css_allocator_fn alloc; void *pw; }; @@ -65,6 +67,9 @@ css_error css_selector_hash_create(lwc_context *dict, memset(h->slots, 0, DEFAULT_SLOTS * sizeof(hash_entry)); h->n_slots = DEFAULT_SLOTS; + h->hash_size = sizeof(css_selector_hash) + + DEFAULT_SLOTS * sizeof(hash_entry); + h->ctx = lwc_context_ref(dict); h->alloc = alloc; h->pw = pw; @@ -163,6 +168,8 @@ css_error css_selector_hash_insert(css_selector_hash *hash, entry->next = prev->next; prev->next = entry; } + + hash->hash_size += sizeof(hash_entry); } return CSS_OK; @@ -216,6 +223,8 @@ css_error css_selector_hash_remove(css_selector_hash *hash, prev->next = head->next; hash->alloc(head, 0, hash->pw); + + hash->hash_size -= sizeof(hash_entry); } return CSS_OK; @@ -317,6 +326,26 @@ css_error css_selector_hash_iterate(css_selector_hash *hash, return CSS_OK; } +/** + * Determine the memory-resident size of a hash + * + * \param hash Hash to consider + * \param size Pointer to location to receive byte count + * \return CSS_OK on success. + * + * \note The returned size will represent the size of the hash datastructures, + * and will not include the size of the data stored in the hash. + */ +css_error css_selector_hash_size(css_selector_hash *hash, size_t *size) +{ + if (hash == NULL || size == NULL) + return CSS_BADPARM; + + *size = hash->hash_size; + + return CSS_OK; +} + /****************************************************************************** * Private functions * ******************************************************************************/ diff --git a/src/select/hash.h b/src/select/hash.h index 59c8b76..9beaa6b 100644 --- a/src/select/hash.h +++ b/src/select/hash.h @@ -35,5 +35,7 @@ css_error css_selector_hash_iterate(css_selector_hash *hash, const struct css_selector **current, const struct css_selector ***next); +css_error css_selector_hash_size(css_selector_hash *hash, size_t *size); + #endif -- cgit v1.2.3