atom: a string is greater than its prefix Bug accidentally introduced in 9a92b46. Signed-off-by: Ran Benita <ran@unusedvar.com>
diff --git a/src/atom.c b/src/atom.c
index 86d02cb..c17fd66 100644
--- a/src/atom.c
+++ b/src/atom.c
@@ -158,23 +158,23 @@ atom_intern(struct atom_table *table, const char *string, size_t len, bool add)
while (*atomp != XKB_ATOM_NONE) {
struct atom_node *node = &darray_item(table->table, *atomp);
- if (fingerprint < node->fingerprint) {
- atomp = &node->left;
- }
- else if (fingerprint > node->fingerprint) {
+ if (fingerprint > node->fingerprint) {
atomp = &node->right;
}
+ else if (fingerprint < node->fingerprint) {
+ atomp = &node->left;
+ }
else {
/* Now start testing the strings. */
const int cmp = strncmp(string, node->string, len);
- if (cmp == 0 && node->string[len] == '\0') {
+ if (likely(cmp == 0 && node->string[len] == '\0')) {
return *atomp;
}
- else if (cmp < 0) {
- atomp = &node->left;
+ else if (cmp > 0) {
+ atomp = &node->right;
}
else {
- atomp = &node->right;
+ atomp = &node->left;
}
}
}