commit 9c0ff5a: [Fix] Fix copy&paste error and rework
Vsevolod Stakhov
vsevolod at highsecure.ru
Thu Jul 22 12:28:05 UTC 2021
Author: Vsevolod Stakhov
Date: 2021-07-22 13:21:29 +0100
URL: https://github.com/rspamd/rspamd/commit/9c0ff5a17da7fbe3007654fc97300dbe67cfe865 (HEAD -> master)
[Fix] Fix copy&paste error and rework
---
src/libserver/composites/composites_internal.hxx | 14 ++++++++++++++
src/libserver/composites/composites_manager.cxx | 18 ++----------------
2 files changed, 16 insertions(+), 16 deletions(-)
diff --git a/src/libserver/composites/composites_internal.hxx b/src/libserver/composites/composites_internal.hxx
index c38f3d377..d6c8f3d69 100644
--- a/src/libserver/composites/composites_internal.hxx
+++ b/src/libserver/composites/composites_internal.hxx
@@ -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 */
diff --git a/src/libserver/composites/composites_manager.cxx b/src/libserver/composites/composites_manager.cxx
index cf91d1136..cbd460be6 100644
--- a/src/libserver/composites/composites_manager.cxx
+++ b/src/libserver/composites/composites_manager.cxx
@@ -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();
}
}
More information about the Commits
mailing list