summaryrefslogtreecommitdiff
path: root/src/select
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2009-07-27 19:38:34 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2009-07-27 19:38:34 +0000
commitfc6b96707730c54fb7ac4040680d79864169b5e0 (patch)
treeb26b5cc05c4ce87564b679628db3f044972eda3c /src/select
parent854eda8b63cc260524a5ec3e3681308b382c7060 (diff)
downloadlibcss-fc6b96707730c54fb7ac4040680d79864169b5e0.tar.gz
libcss-fc6b96707730c54fb7ac4040680d79864169b5e0.tar.bz2
Calculate the in-memory size of stylesheets and provide some API to access this.
svn path=/trunk/libcss/; revision=8830
Diffstat (limited to 'src/select')
-rw-r--r--src/select/hash.c29
-rw-r--r--src/select/hash.h2
2 files changed, 31 insertions, 0 deletions
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