From ffb610c943154afdcaad949e7b0db93fd9047b2b Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Sat, 31 Mar 2012 02:26:24 +0300 Subject: [PATCH] Remove useless check from xkb_intern_atom The "makeit" variable is always true. Remove it and de-indent. (Also change the type of the "len" variable to size_t to avoid some useless casting). Signed-off-by: Ran Benita --- src/atom.c | 84 +++++++++++++++++++++++++++++--------------------------------- 1 file changed, 39 insertions(+), 45 deletions(-) diff --git a/src/atom.c b/src/atom.c index f39ba45..f26e23a 100644 --- a/src/atom.c +++ b/src/atom.c @@ -89,9 +89,9 @@ typedef struct _Node { #define BAD_RESOURCE 0xe0000000 static xkb_atom_t lastAtom = XKB_ATOM_NONE; -static NodePtr atomRoot = NULL; +static NodePtr atomRoot; static unsigned long tableLength; -static NodePtr *nodeTable = NULL; +static NodePtr *nodeTable; const char * XkbcAtomText(xkb_atom_t atom) @@ -116,11 +116,11 @@ xkb_atom_t xkb_intern_atom(const char *string) { NodePtr *np; + NodePtr nd; unsigned i; int comp; unsigned int fp = 0; - unsigned len; - int makeit = True; + size_t len; if (!string) return XKB_ATOM_NONE; @@ -139,7 +139,7 @@ xkb_intern_atom(const char *string) np = &((*np)->right); else { /* now start testing the strings */ - comp = strncmp(string, (*np)->string, (int)len); + comp = strncmp(string, (*np)->string, len); if ((comp < 0) || ((comp == 0) && (len < strlen((*np)->string)))) np = &((*np)->left); else if (comp > 0) @@ -149,53 +149,47 @@ xkb_intern_atom(const char *string) } } - if (makeit) { - NodePtr nd; + nd = malloc(sizeof(NodeRec)); + if (!nd) + return BAD_RESOURCE; - nd = malloc(sizeof(NodeRec)); - if (!nd) - return BAD_RESOURCE; - - nd->string = malloc(len + 1); - if (!nd->string) { + nd->string = malloc(len + 1); + if (!nd->string) { + free(nd); + return BAD_RESOURCE; + } + strncpy(nd->string, string, len); + nd->string[len] = 0; + + if ((lastAtom + 1) >= tableLength) { + NodePtr *table; + int newLength; + + if (tableLength == 0) + newLength = InitialTableSize; + else + newLength = tableLength * 2; + + table = realloc(nodeTable, newLength * sizeof(NodePtr)); + if (!table) { + if (nd->string != string) + free(nd->string); free(nd); return BAD_RESOURCE; } - strncpy(nd->string, string, (int)len); - nd->string[len] = 0; - - if ((lastAtom + 1) >= tableLength) { - NodePtr *table; - int newLength; - - if (tableLength == 0) - newLength = InitialTableSize; - else - newLength = tableLength * 2; - - table = realloc(nodeTable, newLength * sizeof(NodePtr)); - if (!table) { - if (nd->string != string) - free(nd->string); - free(nd); - return BAD_RESOURCE; - } - tableLength = newLength; - table[XKB_ATOM_NONE] = NULL; + tableLength = newLength; + table[XKB_ATOM_NONE] = NULL; - nodeTable = table; - } + nodeTable = table; + } - *np = nd; - nd->left = nd->right = NULL; - nd->fingerPrint = fp; - nd->a = (++lastAtom); - *(nodeTable + lastAtom) = nd; + *np = nd; + nd->left = nd->right = NULL; + nd->fingerPrint = fp; + nd->a = (++lastAtom); + *(nodeTable + lastAtom) = nd; - return nd->a; - } - else - return XKB_ATOM_NONE; + return nd->a; } static void -- 2.7.4