summaryrefslogtreecommitdiff
path: root/src/upb_table.c
diff options
context:
space:
mode:
authorJoshua Haberman <joshua@reverberate.org>2010-07-03 19:19:36 -0700
committerJoshua Haberman <joshua@reverberate.org>2010-07-03 19:19:36 -0700
commit9d051254b35b2bf838f1753a24fe490fb448e428 (patch)
tree362cf3a0ff040b2eeccbbb530b9e60aeb13b05ab /src/upb_table.c
parent5ea7f943f9fd70fa1ada694b4532b71af55f8861 (diff)
Implemented upb_baredecoder, for bootstrapping.
Diffstat (limited to 'src/upb_table.c')
-rw-r--r--src/upb_table.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/upb_table.c b/src/upb_table.c
index 51a9f21..6fd2c20 100644
--- a/src/upb_table.c
+++ b/src/upb_table.c
@@ -57,19 +57,19 @@ void upb_strtable_free(upb_strtable *t) {
upb_table_free(&t->t);
}
-static uint32_t strtable_bucket(upb_strtable *t, upb_strptr key)
+static uint32_t strtable_bucket(upb_strtable *t, upb_string *key)
{
- uint32_t hash = MurmurHash2(upb_string_getrobuf(key), upb_strlen(key), 0);
+ uint32_t hash = MurmurHash2(upb_string_getrobuf(key), upb_string_len(key), 0);
return (hash & (upb_strtable_size(t)-1)) + 1;
}
-void *upb_strtable_lookup(upb_strtable *t, upb_strptr key)
+void *upb_strtable_lookup(upb_strtable *t, upb_string *key)
{
uint32_t bucket = strtable_bucket(t, key);
upb_strtable_entry *e;
do {
e = strent(t, bucket);
- if(!upb_string_isnull(e->key) && upb_streql(e->key, key)) return e;
+ if(e->key && upb_streql(e->key, key)) return e;
} while((bucket = e->next) != UPB_END_OF_CHAIN);
return NULL;
}
@@ -149,7 +149,7 @@ static uint32_t empty_strbucket(upb_strtable *table)
/* TODO: does it matter that this is biased towards the front of the table? */
for(uint32_t i = 1; i <= upb_strtable_size(table); i++) {
upb_strtable_entry *e = strent(table, i);
- if(upb_string_isnull(e->key)) return i;
+ if(!e->key) return i;
}
assert(false);
return 0;
@@ -158,11 +158,11 @@ static uint32_t empty_strbucket(upb_strtable *table)
static void strinsert(upb_strtable *t, upb_strtable_entry *e)
{
assert(upb_strtable_lookup(t, e->key) == NULL);
- e->key = upb_string_getref(e->key, UPB_REF_FROZEN);
+ e->key = upb_string_getref(e->key);
t->t.count++;
uint32_t bucket = strtable_bucket(t, e->key);
upb_strtable_entry *table_e = strent(t, bucket);
- if(!upb_string_isnull(table_e->key)) { /* Collision. */
+ if(table_e->key) { /* Collision. */
if(bucket == strtable_bucket(t, table_e->key)) {
/* Existing element is in its main posisiton. Find an empty slot to
* place our new element and append it to this key's chain. */
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback