]> diplodocus.org Git - nmh/commitdiff
Hoick FENDNULL(key) out of the search loop.
authorRalph Corderoy <ralph@inputplus.co.uk>
Tue, 12 Sep 2017 14:02:41 +0000 (15:02 +0100)
committerRalph Corderoy <ralph@inputplus.co.uk>
Tue, 12 Sep 2017 14:13:26 +0000 (15:13 +0100)
`key' is a loop-invariant so can be tested for NULL once before the
loop.  In one case, this also avoid passing NULL to printf(3) for "%s",
and means getcpy()s can be replaced with mh_xstrdup()s.

sbr/context_del.c
sbr/context_find.c
sbr/context_replace.c
uip/post.c

index 59e3be702111b610d07aed06762193d9016c53da..592af0cad34e0d0e17593283274fc2007eb7ba16 100644 (file)
@@ -18,8 +18,9 @@ context_del (char *key)
 {
     struct node *np, *pp;
 
+    key = FENDNULL(key);
     for (np = m_defs, pp = NULL; np; pp = np, np = np->n_next) {
-       if (!strcasecmp (FENDNULL(np->n_name), FENDNULL(key))) {
+       if (!strcasecmp(FENDNULL(np->n_name), key)) {
            if (!np->n_context)
                inform("bug: context_del(key=\"%s\"), continuing...", np->n_name);
            if (pp)
index afeff37ec3e4c54c5289417ba9ce8ef9f3253162..c6ae2d8c8b14ae1f57faef9e1498049f61a315d0 100644 (file)
@@ -13,8 +13,9 @@ context_find (const char *str)
 {
     struct node *np;
 
+    str = FENDNULL(str);
     for (np = m_defs; np; np = np->n_next)
-       if (!strcasecmp (FENDNULL(np->n_name), FENDNULL(str)))
+       if (!strcasecmp(FENDNULL(np->n_name), str))
            return (np->n_field);
 
     return NULL;
index 0fdd7b4e282440c532de7edf8ddaab0bd15d4770..154f3f6b96f8cc195a23d621ced5c6f9d6bd48e3 100644 (file)
@@ -14,13 +14,15 @@ context_replace (char *key, char *value)
 {
     struct node *np;
 
+    key = FENDNULL(key);
+
     /*
      * If list is empty, allocate head of profile/context list.
      */
     if (!m_defs) {
        NEW(np);
         m_defs = np;
-       np->n_name = getcpy (key);
+       np->n_name = mh_xstrdup(key);
        np->n_field = getcpy (value);
        np->n_context = 1;
        np->n_next = NULL;
@@ -33,7 +35,7 @@ context_replace (char *key, char *value)
      * this key, and replace its value if found.
      */
     for (np = m_defs;; np = np->n_next) {
-       if (!strcasecmp (FENDNULL(np->n_name), FENDNULL(key))) {
+       if (!strcasecmp(FENDNULL(np->n_name), key)) {
            if (strcmp (value, np->n_field)) {
                if (!np->n_context)
                    inform("bug: context_replace(key=\"%s\",value=\"%s\"), continuing...", key, value);
@@ -52,7 +54,7 @@ context_replace (char *key, char *value)
      */
     NEW(np->n_next);
     np = np->n_next;
-    np->n_name = getcpy (key);
+    np->n_name = mh_xstrdup(key);
     np->n_field = getcpy (value);
     np->n_context = 1;
     np->n_next = NULL;
index 69fe6b86c2c62ec1458badda67f56317e5321c28..7cbf9dc96c6e7440a659ac915ff1cdbd0ae88e19 100644 (file)
@@ -1221,8 +1221,9 @@ get_header (char *header, struct headers *table)
 {
     struct headers *h;
 
+    header = FENDNULL(header);
     for (h = table; h->value; h++)
-       if (!strcasecmp (FENDNULL(header), FENDNULL(h->value)))
+       if (!strcasecmp(FENDNULL(h->value), header))
            return (h - table);
 
     return NOTOK;