From aecae495bd23fac2a8ec63add02b45ad46ff6edd Mon Sep 17 00:00:00 2001 From: Matteo Nicoli Date: Sat, 25 Jan 2025 02:50:16 +0100 Subject: [PATCH] review fix --- components/core/src/clp/DictionaryReader.hpp | 3 ++- .../core/src/clp/EncodedVariableInterpreter.cpp | 11 +++++------ components/core/src/clp_s/DictionaryReader.hpp | 3 ++- components/core/src/clp_s/search/Output.cpp | 4 ++-- .../search/clp_search/EncodedVariableInterpreter.cpp | 9 ++++----- .../core/tests/test-EncodedVariableInterpreter.cpp | 12 ++++++++---- 6 files changed, 23 insertions(+), 19 deletions(-) diff --git a/components/core/src/clp/DictionaryReader.hpp b/components/core/src/clp/DictionaryReader.hpp index a994fe091..6dfaa282b 100644 --- a/components/core/src/clp/DictionaryReader.hpp +++ b/components/core/src/clp/DictionaryReader.hpp @@ -243,7 +243,8 @@ DictionaryReader::get_entry_matching_value( for (auto const& entry : m_entries) { if (entry.get_value() == search_string) { entries.push_back(&entry); - return entries; /* early exit for case sensitive branch */ + // early exit for case sensitive branch + return entries; } } } else { diff --git a/components/core/src/clp/EncodedVariableInterpreter.cpp b/components/core/src/clp/EncodedVariableInterpreter.cpp index e05803b61..6a64e2542 100644 --- a/components/core/src/clp/EncodedVariableInterpreter.cpp +++ b/components/core/src/clp/EncodedVariableInterpreter.cpp @@ -386,8 +386,7 @@ bool EncodedVariableInterpreter::encode_and_search_dictionary( LogTypeDictionaryEntry::add_float_var(logtype); sub_query.add_non_dict_var(encoded_var); } else { - auto entries = var_dict.get_entry_matching_value(var_str, ignore_case); - + auto const entries = var_dict.get_entry_matching_value(var_str, ignore_case); if (entries.empty()) { // Not in dictionary return false; @@ -396,18 +395,18 @@ bool EncodedVariableInterpreter::encode_and_search_dictionary( LogTypeDictionaryEntry::add_dict_var(logtype); if (entries.size() == 1) { - clp::VariableDictionaryEntry const* entry = entries[0]; - auto encoded_var = encode_var_dict_id(entry->get_id()); + auto const* entry = entries.at(0); + encoded_var = encode_var_dict_id(entry->get_id()); sub_query.add_dict_var(encoded_var, entry); return true; } std::unordered_set encoded_vars; - std::unordered_set entries_set( + std::unordered_set const entries_set( entries.begin(), entries.end() ); - for (auto entry : entries) { + for (auto const entry : entries) { encoded_vars.insert(encode_var_dict_id(entry->get_id())); } sub_query.add_imprecise_dict_var(encoded_vars, entries_set); diff --git a/components/core/src/clp_s/DictionaryReader.hpp b/components/core/src/clp_s/DictionaryReader.hpp index 20b63fd8d..2d44b1a19 100644 --- a/components/core/src/clp_s/DictionaryReader.hpp +++ b/components/core/src/clp_s/DictionaryReader.hpp @@ -166,7 +166,8 @@ DictionaryReader::get_entry_matching_value( for (auto const& entry : m_entries) { if (entry.get_value() == search_string) { entries.push_back(&entry); - return entries; /* early exit for case sensitive branch */ + // early exit for case sensitive branch + return entries; } } } else { diff --git a/components/core/src/clp_s/search/Output.cpp b/components/core/src/clp_s/search/Output.cpp index e2c268b79..6276c346b 100644 --- a/components/core/src/clp_s/search/Output.cpp +++ b/components/core/src/clp_s/search/Output.cpp @@ -932,12 +932,12 @@ void Output::populate_string_queries(std::shared_ptr const& expr) { } } - auto entries = m_var_dict->get_entry_matching_value( + auto const entries = m_var_dict->get_entry_matching_value( unescaped_query_string, m_ignore_case ); - for (auto entry : entries) { + for (auto const& entry : entries) { matching_vars.insert(entry->get_id()); } } else if (EncodedVariableInterpreter:: diff --git a/components/core/src/clp_s/search/clp_search/EncodedVariableInterpreter.cpp b/components/core/src/clp_s/search/clp_search/EncodedVariableInterpreter.cpp index b77537b06..5d589d003 100644 --- a/components/core/src/clp_s/search/clp_search/EncodedVariableInterpreter.cpp +++ b/components/core/src/clp_s/search/clp_search/EncodedVariableInterpreter.cpp @@ -34,8 +34,7 @@ bool EncodedVariableInterpreter::encode_and_search_dictionary( LogTypeDictionaryEntry::add_double_var(logtype); sub_query.add_non_dict_var(encoded_var); } else { - auto entries = var_dict.get_entry_matching_value(var_str, ignore_case); - + auto const entries = var_dict.get_entry_matching_value(var_str, ignore_case); if (entries.empty()) { // Not in dictionary return false; @@ -44,8 +43,8 @@ bool EncodedVariableInterpreter::encode_and_search_dictionary( LogTypeDictionaryEntry::add_non_double_var(logtype); if (entries.size() == 1) { - VariableDictionaryEntry const* entry = entries[0]; - auto encoded_var = VariableEncoder::encode_var_dict_id(entry->get_id()); + auto const* entry = entries.at(0); + encoded_var = VariableEncoder::encode_var_dict_id(entry->get_id()); sub_query.add_dict_var(encoded_var, entry); return true; } @@ -55,7 +54,7 @@ bool EncodedVariableInterpreter::encode_and_search_dictionary( entries.begin(), entries.end() ); - for (auto entry : entries) { + for (auto const entry : entries) { encoded_vars.insert(VariableEncoder::encode_var_dict_id(entry->get_id())); } sub_query.add_imprecise_dict_var(encoded_vars, entries_set); diff --git a/components/core/tests/test-EncodedVariableInterpreter.cpp b/components/core/tests/test-EncodedVariableInterpreter.cpp index 70b990bc4..3568c2bbb 100644 --- a/components/core/tests/test-EncodedVariableInterpreter.cpp +++ b/components/core/tests/test-EncodedVariableInterpreter.cpp @@ -381,13 +381,17 @@ TEST_CASE("EncodedVariableInterpreter", "[EncodedVariableInterpreter]") { char const cVarSegmentIndexPath[] = "var.segindex"; vector var_strs = {"python2.7.3", "Python2.7.3", "PyThOn2.7.3", "PYTHON2.7.3"}; clp::VariableDictionaryWriter var_dict_writer; + var_dict_writer.open(cVarDictPath, cVarSegmentIndexPath, cVariableDictionaryIdMax); + vector encoded_vars; vector var_ids; clp::LogTypeDictionaryEntry logtype_dict_entry; - for (auto var_str : var_strs) { + string const msg_template = "here is a string with a dictionary var: "; + + for (auto const& var_str : var_strs) { EncodedVariableInterpreter::encode_and_add_to_dictionary( - var_str, + msg_template + var_str, logtype_dict_entry, var_dict_writer, encoded_vars, @@ -400,9 +404,9 @@ TEST_CASE("EncodedVariableInterpreter", "[EncodedVariableInterpreter]") { var_dict_reader.open(cVarDictPath, cVarSegmentIndexPath); var_dict_reader.read_new_entries(); - REQUIRE(var_dict_reader.get_entry_matching_value(var_strs[0], true).size() + REQUIRE(var_dict_reader.get_entry_matching_value(var_strs.at(0), true).size() == var_strs.size()); - REQUIRE(var_dict_reader.get_entry_matching_value(var_strs[0], false).size() == 1); + REQUIRE(var_dict_reader.get_entry_matching_value(var_strs.at(0), false).size() == 1); var_dict_reader.close();