Rework key prefix matching

Use C string comparison instead of C++ function std::mismatch to increase
performance.
This commit is contained in:
Christian Gruber 2020-02-02 17:55:30 +01:00
parent a13184978a
commit 322f2d99de

View File

@ -242,11 +242,8 @@ void KvpFrame::for_each_slot_prefix(std::string const & prefix,
std::for_each (m_valuemap.begin(), m_valuemap.end(),
[&prefix,&func](const KvpFrameImpl::map_type::value_type & a)
{
std::string temp_key {a.first};
if (temp_key.size() < prefix.size())
return;
/* Testing for prefix matching */
if (std::mismatch(prefix.begin(), prefix.end(), temp_key.begin()).first == prefix.end())
if (strncmp(a.first, prefix.c_str(), prefix.size()) == 0)
func (&a.first[prefix.size()], a.second);
}
);
@ -259,11 +256,8 @@ void KvpFrame::for_each_slot_prefix(std::string const & prefix,
std::for_each (m_valuemap.begin(), m_valuemap.end(),
[&prefix,&func,&data](const KvpFrameImpl::map_type::value_type & a)
{
std::string temp_key {a.first};
if (temp_key.size() < prefix.size())
return;
/* Testing for prefix matching */
if (std::mismatch(prefix.begin(), prefix.end(), temp_key.begin()).first == prefix.end())
if (strncmp(a.first, prefix.c_str(), prefix.size()) == 0)
func (&a.first[prefix.size()], a.second, data);
}
);