From 322f2d99de89849b4d193afcb779520aabcafa4f Mon Sep 17 00:00:00 2001 From: Christian Gruber Date: Sun, 2 Feb 2020 17:55:30 +0100 Subject: [PATCH] Rework key prefix matching Use C string comparison instead of C++ function std::mismatch to increase performance. --- libgnucash/engine/kvp-frame.hpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/libgnucash/engine/kvp-frame.hpp b/libgnucash/engine/kvp-frame.hpp index 1419e626e5..c84cf18a4d 100644 --- a/libgnucash/engine/kvp-frame.hpp +++ b/libgnucash/engine/kvp-frame.hpp @@ -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); } );