summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/atom.c32
-rw-r--r--src/atom.h5
-rw-r--r--src/context-priv.c4
3 files changed, 7 insertions, 34 deletions
diff --git a/src/atom.c b/src/atom.c
index e78c68f..86d02cb 100644
--- a/src/atom.c
+++ b/src/atom.c
@@ -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;
}
diff --git a/src/atom.h b/src/atom.h
index f936911..49478db 100644
--- a/src/atom.h
+++ b/src/atom.h
@@ -37,10 +37,7 @@ void
atom_table_free(struct atom_table *table);
xkb_atom_t
-atom_lookup(struct atom_table *table, const char *string, size_t len);
-
-xkb_atom_t
-atom_intern(struct atom_table *table, const char *string, size_t len);
+atom_intern(struct atom_table *table, const char *string, size_t len, bool add);
const char *
atom_text(struct atom_table *table, xkb_atom_t atom);
diff --git a/src/context-priv.c b/src/context-priv.c
index e3ba32d..03324fd 100644
--- a/src/context-priv.c
+++ b/src/context-priv.c
@@ -52,13 +52,13 @@ xkb_context_failed_include_path_get(struct xkb_context *ctx,
xkb_atom_t
xkb_atom_lookup(struct xkb_context *ctx, const char *string)
{
- return atom_lookup(ctx->atom_table, string, strlen(string));
+ return atom_intern(ctx->atom_table, string, strlen(string), false);
}
xkb_atom_t
xkb_atom_intern(struct xkb_context *ctx, const char *string, size_t len)
{
- return atom_intern(ctx->atom_table, string, len);
+ return atom_intern(ctx->atom_table, string, len, true);
}
const char *