]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Improve composites processing strncmp -> memcmp
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 8 Dec 2020 13:53:29 +0000 (13:53 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 8 Dec 2020 13:53:29 +0000 (13:53 +0000)
src/libserver/composites.c

index 3ec7704394eb2945f5a57bbd3653f87644a5911e..7a5289441c8b48385e6a412493fd975349e68b2a 100644 (file)
@@ -611,51 +611,23 @@ rspamd_composite_expr_process (void *ud,
        }
 
        sym = comp_atom->symbol;
+       guint slen = strlen (sym);
 
        while (*sym != '\0' && !g_ascii_isalnum (*sym)) {
                sym ++;
+               slen --;
        }
 
-       if (strncmp (sym, "g:", 2) == 0) {
-               gr = g_hash_table_lookup (cd->task->cfg->groups, sym + 2);
+       if (slen > 2) {
+               if (G_UNLIKELY (memcmp (sym, "g:", 2) == 0)) {
+                       gr = g_hash_table_lookup (cd->task->cfg->groups, sym + 2);
 
-               if (gr != NULL) {
-                       g_hash_table_iter_init (&it, gr->symbols);
+                       if (gr != NULL) {
+                               g_hash_table_iter_init (&it, gr->symbols);
 
-                       while (g_hash_table_iter_next (&it, &k, &v)) {
-                               sdef = v;
-                               rc = rspamd_composite_process_single_symbol (cd, sdef->name, &ms,
-                                               comp_atom);
-
-                               if (rc) {
-                                       rspamd_composite_process_symbol_removal (atom,
-                                                       cd,
-                                                       ms,
-                                                       comp_atom->symbol);
-
-                                       if (fabs (rc) > max) {
-                                               max = fabs (rc);
-                                       }
-                               }
-                       }
-               }
-
-               rc = max;
-       }
-       else if (strncmp (sym, "g+:", 3) == 0) {
-               /* Group, positive symbols only */
-               gr = g_hash_table_lookup (cd->task->cfg->groups, sym + 3);
-
-               if (gr != NULL) {
-                       g_hash_table_iter_init (&it, gr->symbols);
-
-                       while (g_hash_table_iter_next (&it, &k, &v)) {
-                               sdef = v;
-
-                               if (sdef->score > 0) {
-                                       rc = rspamd_composite_process_single_symbol (cd,
-                                                       sdef->name,
-                                                       &ms,
+                               while (g_hash_table_iter_next (&it, &k, &v)) {
+                                       sdef = v;
+                                       rc = rspamd_composite_process_single_symbol (cd, sdef->name, &ms,
                                                        comp_atom);
 
                                        if (rc) {
@@ -673,37 +645,79 @@ rspamd_composite_expr_process (void *ud,
 
                        rc = max;
                }
-       }
-       else if (strncmp (sym, "g-:", 3) == 0) {
-               /* Group, negative symbols only */
-               gr = g_hash_table_lookup (cd->task->cfg->groups, sym + 3);
-
-               if (gr != NULL) {
-                       g_hash_table_iter_init (&it, gr->symbols);
-
-                       while (g_hash_table_iter_next (&it, &k, &v)) {
-                               sdef = v;
-
-                               if (sdef->score < 0) {
-                                       rc = rspamd_composite_process_single_symbol (cd,
-                                                       sdef->name,
-                                                       &ms,
-                                                       comp_atom);
-
-                                       if (rc) {
-                                               rspamd_composite_process_symbol_removal (atom,
-                                                               cd,
-                                                               ms,
-                                                               comp_atom->symbol);
+               else if (G_UNLIKELY (memcmp (sym, "g+:", 3) == 0)) {
+                       /* Group, positive symbols only */
+                       gr = g_hash_table_lookup (cd->task->cfg->groups, sym + 3);
+
+                       if (gr != NULL) {
+                               g_hash_table_iter_init (&it, gr->symbols);
+
+                               while (g_hash_table_iter_next (&it, &k, &v)) {
+                                       sdef = v;
+
+                                       if (sdef->score > 0) {
+                                               rc = rspamd_composite_process_single_symbol (cd,
+                                                               sdef->name,
+                                                               &ms,
+                                                               comp_atom);
+
+                                               if (rc) {
+                                                       rspamd_composite_process_symbol_removal (atom,
+                                                                       cd,
+                                                                       ms,
+                                                                       comp_atom->symbol);
+
+                                                       if (fabs (rc) > max) {
+                                                               max = fabs (rc);
+                                                       }
+                                               }
+                                       }
+                               }
 
-                                               if (fabs (rc) > max) {
-                                                       max = fabs (rc);
+                               rc = max;
+                       }
+               }
+               else if (G_UNLIKELY (memcmp (sym, "g-:", 3) == 0)) {
+                       /* Group, negative symbols only */
+                       gr = g_hash_table_lookup (cd->task->cfg->groups, sym + 3);
+
+                       if (gr != NULL) {
+                               g_hash_table_iter_init (&it, gr->symbols);
+
+                               while (g_hash_table_iter_next (&it, &k, &v)) {
+                                       sdef = v;
+
+                                       if (sdef->score < 0) {
+                                               rc = rspamd_composite_process_single_symbol (cd,
+                                                               sdef->name,
+                                                               &ms,
+                                                               comp_atom);
+
+                                               if (rc) {
+                                                       rspamd_composite_process_symbol_removal (atom,
+                                                                       cd,
+                                                                       ms,
+                                                                       comp_atom->symbol);
+
+                                                       if (fabs (rc) > max) {
+                                                               max = fabs (rc);
+                                                       }
                                                }
                                        }
                                }
+
+                               rc = max;
                        }
+               }
+               else {
+                       rc = rspamd_composite_process_single_symbol (cd, sym, &ms, comp_atom);
 
-                       rc = max;
+                       if (rc) {
+                               rspamd_composite_process_symbol_removal (atom,
+                                               cd,
+                                               ms,
+                                               comp_atom->symbol);
+                       }
                }
        }
        else {