atom: expand variable names A bit easier to understand at a glance. Signed-off-by: Ran Benita <ran234@gmail.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 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
diff --git a/src/atom.c b/src/atom.c
index a775023..8edf465 100644
--- a/src/atom.c
+++ b/src/atom.c
@@ -142,37 +142,35 @@ atom_strdup(struct atom_table *table, xkb_atom_t atom)
static bool
find_node_pointer(struct atom_table *table, const char *string,
- struct atom_node ***np_out, unsigned int *fingerprint_out)
+ struct atom_node ***nodep_out, unsigned int *fingerprint_out)
{
- struct atom_node **np;
- unsigned i;
- int comp;
- unsigned int fp = 0;
+ struct atom_node **nodep;
+ unsigned int fingerprint = 0;
size_t len;
bool found = false;
len = strlen(string);
- np = &table->root;
- for (i = 0; i < (len + 1) / 2; i++) {
- fp = fp * 27 + string[i];
- fp = fp * 27 + string[len - 1 - i];
+ nodep = &table->root;
+ for (size_t i = 0; i < (len + 1) / 2; i++) {
+ fingerprint = fingerprint * 27 + string[i];
+ fingerprint = fingerprint * 27 + string[len - 1 - i];
}
- while (*np) {
- if (fp < (*np)->fingerprint) {
- np = &((*np)->left);
+ while (*nodep) {
+ if (fingerprint < (*nodep)->fingerprint) {
+ nodep = &((*nodep)->left);
}
- else if (fp > (*np)->fingerprint) {
- np = &((*np)->right);
+ else if (fingerprint > (*nodep)->fingerprint) {
+ nodep = &((*nodep)->right);
}
else {
- /* now start testing the strings */
- comp = strncmp(string, (*np)->string, len);
- if (comp < 0 || (comp == 0 && len < strlen((*np)->string))) {
- np = &((*np)->left);
+ /* Now start testing the strings. */
+ const int cmp = strncmp(string, (*nodep)->string, len);
+ if (cmp < 0 || (cmp == 0 && len < strlen((*nodep)->string))) {
+ nodep = &((*nodep)->left);
}
- else if (comp > 0) {
- np = &((*np)->right);
+ else if (cmp > 0) {
+ nodep = &((*nodep)->right);
}
else {
found = true;
@@ -181,24 +179,24 @@ find_node_pointer(struct atom_table *table, const char *string,
}
}
- *fingerprint_out = fp;
- *np_out = np;
+ *fingerprint_out = fingerprint;
+ *nodep_out = nodep;
return found;
}
xkb_atom_t
atom_lookup(struct atom_table *table, const char *string)
{
- struct atom_node **np;
- unsigned int fp;
+ struct atom_node **nodep;
+ unsigned int fingerprint;
if (!string)
return XKB_ATOM_NONE;
- if (!find_node_pointer(table, string, &np, &fp))
+ if (!find_node_pointer(table, string, &nodep, &fingerprint))
return XKB_ATOM_NONE;
- return (*np)->atom;
+ return (*nodep)->atom;
}
/*
@@ -207,42 +205,41 @@ atom_lookup(struct atom_table *table, const char *string)
* 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, bool steal)
{
- struct atom_node **np;
- struct atom_node *nd;
- unsigned int fp;
+ struct atom_node **nodep;
+ struct atom_node *node;
+ unsigned int fingerprint;
if (!string)
return XKB_ATOM_NONE;
- if (find_node_pointer(table, string, &np, &fp)) {
+ if (find_node_pointer(table, string, &nodep, &fingerprint)) {
if (steal)
free(UNCONSTIFY(string));
- return (*np)->atom;
+ return (*nodep)->atom;
}
- nd = malloc(sizeof(*nd));
- if (!nd)
+ node = malloc(sizeof(*node));
+ if (!node)
return XKB_ATOM_NONE;
if (steal) {
- nd->string = UNCONSTIFY(string);
+ node->string = UNCONSTIFY(string);
}
else {
- nd->string = strdup(string);
- if (!nd->string) {
- free(nd);
+ node->string = strdup(string);
+ if (!node->string) {
+ free(node);
return XKB_ATOM_NONE;
}
}
- *np = nd;
- nd->left = nd->right = NULL;
- nd->fingerprint = fp;
- nd->atom = darray_size(table->table);
- darray_append(table->table, nd);
+ *nodep = node;
+ node->left = node->right = NULL;
+ node->fingerprint = fingerprint;
+ node->atom = darray_size(table->table);
+ darray_append(table->table, node);
- return nd->atom;
+ return node->atom;
}
diff --git a/src/atom.h b/src/atom.h
index f1abf1b..7ee7acc 100644
--- a/src/atom.h
+++ b/src/atom.h
@@ -40,8 +40,7 @@ xkb_atom_t
atom_lookup(struct atom_table *table, const char *string);
xkb_atom_t
-atom_intern(struct atom_table *table, const char *string,
- bool steal);
+atom_intern(struct atom_table *table, const char *string, bool steal);
char *
atom_strdup(struct atom_table *table, xkb_atom_t atom);