We need this later. The strlen was calculated anyway, so no loss here.
Signed-off-by: Ran Benita <ran234@gmail.com>
-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;
struct atom_node ***nodep_out, unsigned int *fingerprint_out)
{
struct atom_node **nodep;
unsigned int fingerprint = 0;
nodep = &table->root;
for (size_t i = 0; i < (len + 1) / 2; i++) {
fingerprint = fingerprint * 27 + string[i];
nodep = &table->root;
for (size_t i = 0; i < (len + 1) / 2; i++) {
fingerprint = fingerprint * 27 + string[i];
-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;
{
struct atom_node **nodep;
unsigned int fingerprint;
if (!string)
return XKB_ATOM_NONE;
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;
return XKB_ATOM_NONE;
return (*nodep)->atom;
/*
* If steal is true, we do not strdup @string; therefore it must be
/*
* 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.
-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;
{
struct atom_node **nodep;
struct atom_node *node;
if (!string)
return XKB_ATOM_NONE;
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;
if (steal)
free(UNCONSTIFY(string));
return (*nodep)->atom;
atom_table_free(struct atom_table *table);
xkb_atom_t
atom_table_free(struct atom_table *table);
xkb_atom_t
-atom_lookup(struct atom_table *table, const char *string);
+atom_lookup(struct atom_table *table, const char *string, size_t len);
-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);
char *
atom_strdup(struct atom_table *table, xkb_atom_t atom);
char *
atom_strdup(struct atom_table *table, xkb_atom_t atom);
xkb_atom_t
xkb_atom_lookup(struct xkb_context *ctx, const char *string)
{
xkb_atom_t
xkb_atom_lookup(struct xkb_context *ctx, const char *string)
{
- return atom_lookup(ctx->atom_table, string);
+ return atom_lookup(ctx->atom_table, string, strlen(string));
}
xkb_atom_t
xkb_atom_intern(struct xkb_context *ctx, const char *string)
{
}
xkb_atom_t
xkb_atom_intern(struct xkb_context *ctx, const char *string)
{
- return atom_intern(ctx->atom_table, string, false);
+ return atom_intern(ctx->atom_table, string, strlen(string), false);
}
xkb_atom_t
xkb_atom_steal(struct xkb_context *ctx, char *string)
{
}
xkb_atom_t
xkb_atom_steal(struct xkb_context *ctx, char *string)
{
- return atom_intern(ctx->atom_table, string, true);
+ return atom_intern(ctx->atom_table, string, strlen(string), true);