diff options
author | Ran Benita <ran@unusedvar.com> | 2019-11-09 21:25:01 +0200 |
---|---|---|
committer | Ran Benita <ran@unusedvar.com> | 2019-11-09 21:28:43 +0200 |
commit | c79c80335be8a60e36b5ad21a05ff351d5bfa3f9 (patch) | |
tree | ee11b84b6a4d7e8137ac4ca8bb278573988fecd4 /src/atom.c | |
parent | adbd9c6f0819a3ddd5a06237238e9becdb036e17 (diff) | |
download | xorg-lib-libxkbcommon-c79c80335be8a60e36b5ad21a05ff351d5bfa3f9.tar.gz |
atom: combine atom_intern() and atom_lookup()
Use an "add" bool parameter instead. This simplifies the code a bit.
Signed-off-by: Ran Benita <ran@unusedvar.com>
Diffstat (limited to 'src/atom.c')
-rw-r--r-- | src/atom.c | 32 |
1 files changed, 4 insertions, 28 deletions
@@ -149,9 +149,8 @@ atom_text(struct atom_table *table, xkb_atom_t atom) return darray_item(table->table, atom).string; } -static bool -find_atom_pointer(struct atom_table *table, const char *string, size_t len, - xkb_atom_t **atomp_out, uint32_t *fingerprint_out) +xkb_atom_t +atom_intern(struct atom_table *table, const char *string, size_t len, bool add) { uint32_t fingerprint = hash_buf(string, len); @@ -169,7 +168,7 @@ find_atom_pointer(struct atom_table *table, const char *string, size_t len, /* Now start testing the strings. */ const int cmp = strncmp(string, node->string, len); if (cmp == 0 && node->string[len] == '\0') { - break; + return *atomp; } else if (cmp < 0) { atomp = &node->left; @@ -180,31 +179,9 @@ find_atom_pointer(struct atom_table *table, const char *string, size_t len, } } - if (fingerprint_out) - *fingerprint_out = fingerprint; - if (atomp_out) - *atomp_out = atomp; - return *atomp != XKB_ATOM_NONE; -} - -xkb_atom_t -atom_lookup(struct atom_table *table, const char *string, size_t len) -{ - xkb_atom_t *atomp; - if (!find_atom_pointer(table, string, len, &atomp, NULL)) + if (!add) return XKB_ATOM_NONE; - return *atomp; -} - -xkb_atom_t -atom_intern(struct atom_table *table, const char *string, size_t len) -{ - xkb_atom_t *atomp; - uint32_t fingerprint; - if (find_atom_pointer(table, string, len, &atomp, &fingerprint)) - return *atomp; - struct atom_node node; node.string = strndup(string, len); assert(node.string != NULL); @@ -214,6 +191,5 @@ atom_intern(struct atom_table *table, const char *string, size_t len) /* Do this before the append, as it may realloc and change the offsets. */ *atomp = atom; darray_append(table->table, node); - return atom; } |