diff options
author | Ran Benita <ran234@gmail.com> | 2013-07-21 16:41:27 +0300 |
---|---|---|
committer | Ran Benita <ran234@gmail.com> | 2013-07-21 17:07:41 +0300 |
commit | 7e0ae4b4d5bfcebd7bf4cefcefe681ea7ecc5f61 (patch) | |
tree | bdd39e92c5d9dacd6facc7d5725d4253bcdfa917 /src/atom.c | |
parent | 9cd29453aec206727adeafe0c27d629d61fe1310 (diff) | |
download | xorg-lib-libxkbcommon-7e0ae4b4d5bfcebd7bf4cefcefe681ea7ecc5f61.tar.gz |
atom: allow interning non-NUL-terminated strings
We need this later. The strlen was calculated anyway, so no loss here.
Signed-off-by: Ran Benita <ran234@gmail.com>
Diffstat (limited to 'src/atom.c')
-rw-r--r-- | src/atom.c | 17 |
1 files changed, 8 insertions, 9 deletions
@@ -141,15 +141,13 @@ atom_strdup(struct atom_table *table, xkb_atom_t atom) } static bool -find_node_pointer(struct atom_table *table, const char *string, +find_node_pointer(struct atom_table *table, const char *string, size_t len, struct atom_node ***nodep_out, unsigned int *fingerprint_out) { struct atom_node **nodep; unsigned int fingerprint = 0; - size_t len; bool found = false; - len = strlen(string); nodep = &table->root; for (size_t i = 0; i < (len + 1) / 2; i++) { fingerprint = fingerprint * 27 + string[i]; @@ -185,7 +183,7 @@ find_node_pointer(struct atom_table *table, const char *string, } xkb_atom_t -atom_lookup(struct atom_table *table, const char *string) +atom_lookup(struct atom_table *table, const char *string, size_t len) { struct atom_node **nodep; unsigned int fingerprint; @@ -193,7 +191,7 @@ atom_lookup(struct atom_table *table, const char *string) if (!string) return XKB_ATOM_NONE; - if (!find_node_pointer(table, string, &nodep, &fingerprint)) + if (!find_node_pointer(table, string, len, &nodep, &fingerprint)) return XKB_ATOM_NONE; return (*nodep)->atom; @@ -201,11 +199,12 @@ atom_lookup(struct atom_table *table, const char *string) /* * If steal is true, we do not strdup @string; therefore it must be - * dynamically allocated, not be free'd by the caller and not be used - * afterwards. Use to avoid some redundant allocations. + * dynamically allocated, NUL-terminated, not be free'd by the caller + * and not be used afterwards. Use to avoid some redundant allocations. */ xkb_atom_t -atom_intern(struct atom_table *table, const char *string, bool steal) +atom_intern(struct atom_table *table, const char *string, size_t len, + bool steal) { struct atom_node **nodep; struct atom_node *node; @@ -214,7 +213,7 @@ atom_intern(struct atom_table *table, const char *string, bool steal) if (!string) return XKB_ATOM_NONE; - if (find_node_pointer(table, string, &nodep, &fingerprint)) { + if (find_node_pointer(table, string, len, &nodep, &fingerprint)) { if (steal) free(UNCONSTIFY(string)); return (*nodep)->atom; |