atom: style changes Signed-off-by: Ran Benita <ran@unusedvar.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
diff --git a/src/atom.c b/src/atom.c
index aa6cfb3..cebc2e7 100644
--- a/src/atom.c
+++ b/src/atom.c
@@ -87,9 +87,7 @@ struct atom_table {
struct atom_table *
atom_table_new(void)
{
- struct atom_table *table;
-
- table = calloc(1, sizeof(*table));
+ struct atom_table *table = calloc(1, sizeof(*table));
if (!table)
return NULL;
@@ -103,11 +101,10 @@ atom_table_new(void)
void
atom_table_free(struct atom_table *table)
{
- struct atom_node *node;
-
if (!table)
return;
+ struct atom_node *node;
darray_foreach(node, table->table)
free(node->string);
darray_free(table->table);
@@ -125,15 +122,13 @@ 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 *atomp = &table->root;
uint32_t fingerprint = 0;
- bool found = false;
-
for (size_t i = 0; i < (len + 1) / 2; i++) {
fingerprint = fingerprint * 27 + string[i];
fingerprint = fingerprint * 27 + string[len - 1 - i];
}
+ xkb_atom_t *atomp = &table->root;
while (*atomp != XKB_ATOM_NONE) {
struct atom_node *node = &darray_item(table->table, *atomp);
@@ -146,15 +141,14 @@ find_atom_pointer(struct atom_table *table, const char *string, size_t len,
else {
/* Now start testing the strings. */
const int cmp = strncmp(string, node->string, len);
- if (cmp < 0 || (cmp == 0 && node->string[len] != '\0')) {
- atomp = &node->left;
+ if (cmp == 0 && node->string[len] == '\0') {
+ break;
}
- else if (cmp > 0) {
- atomp = &node->right;
+ else if (cmp < 0) {
+ atomp = &node->left;
}
else {
- found = true;
- break;
+ atomp = &node->right;
}
}
}
@@ -163,14 +157,13 @@ find_atom_pointer(struct atom_table *table, const char *string, size_t len,
*fingerprint_out = fingerprint;
if (atomp_out)
*atomp_out = atomp;
- return found;
+ 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))
return XKB_ATOM_NONE;
@@ -181,16 +174,13 @@ xkb_atom_t
atom_intern(struct atom_table *table, const char *string, size_t len)
{
xkb_atom_t *atomp;
- struct atom_node node;
uint32_t fingerprint;
-
- if (find_atom_pointer(table, string, len, &atomp, &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);
-
node.left = node.right = XKB_ATOM_NONE;
node.fingerprint = fingerprint;
xkb_atom_t atom = darray_size(table->table);