]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Fix copy&paste error and rework
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 22 Jul 2021 12:21:29 +0000 (13:21 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 22 Jul 2021 12:21:29 +0000 (13:21 +0100)
src/libserver/composites/composites_internal.hxx
src/libserver/composites/composites_manager.cxx

index c38f3d3771acf6a0bf7cecdbb50796b326eba072..d6c8f3d6948c1c9ac12dca9debfaa34a368bb5a8 100644 (file)
@@ -102,6 +102,20 @@ private:
                }
        };
 
+       auto new_composite(std::string_view composite_name, rspamd_expression *expr,
+                                               std::string_view composite_expression) -> auto
+       {
+               auto &composite = all_composites.emplace_back(std::make_shared<rspamd_composite>());
+               composite->expr = expr;
+               composite->id = all_composites.size() - 1;
+               composite->str_expr = composite_expression;
+               composite->sym = composite_name;
+
+               composites[composite->sym] = composite;
+
+               return composite;
+       }
+
        robin_hood::unordered_flat_map<std::string,
                        std::shared_ptr<rspamd_composite>, smart_str_hash, smart_str_equal> composites;
        /* Store all composites here, even if we have duplicates */
index cf91d1136f2a3389250ef97183c59536bc23ff5e..cbd460be6fe51a24d2de166e894060c0f62447ae 100644 (file)
@@ -85,11 +85,7 @@ composites_manager::add_composite(std::string_view composite_name, const ucl_obj
                return nullptr;
        }
 
-       auto &composite = all_composites.emplace_back(std::make_shared<rspamd_composite>());
-       composite->expr = expr;
-       composite->id = all_composites.size() - 1;
-       composite->str_expr = composite_expression;
-       composite->sym = composite_name;
+       const auto &composite = new_composite(composite_name, expr, composite_expression);
 
        double score;
        val = ucl_object_lookup(obj, "score");
@@ -141,8 +137,6 @@ composites_manager::add_composite(std::string_view composite_name, const ucl_obj
                }
        }
 
-       composites[std::string(composite_name)] = composite;
-
        return composite.get();
 }
 
@@ -166,15 +160,7 @@ composites_manager::add_composite(std::string_view composite_name,
                return nullptr;
        }
 
-       auto &composite = all_composites.emplace_back(std::make_shared<rspamd_composite>());
-       composite->expr = expr;
-       composite->id = all_composites.size();
-       composite->str_expr = composite_expression;
-       composite->sym = composite_name;
-
-       composites[std::string(composite_name)] = composite;
-
-       return composite.get();
+       return new_composite(composite_name, expr, composite_expression).get();
 }
 
 }