serialized: don't copy strings in policy lookups 26/249426/1
authorAdrian Szyndela <adrian.s@samsung.com>
Fri, 11 Dec 2020 09:06:16 +0000 (10:06 +0100)
committerAdrian Szyndela <adrian.s@samsung.com>
Fri, 11 Dec 2020 09:11:10 +0000 (10:11 +0100)
Direct serialization allows more optimizing. Now, that other
backends are gone, we can slightly modify the interface.

This commit makes send index searching pass boost::string_ref
to the backend instead of copied C-string. The backend interface
is modified to accept string_ref. This way we can remove
string copying which was necessary for having null-terminated C-string.

Change-Id: I5a1f9657efd050d93023b5256f13afd6d150c369

src/internal/storage_backend_direct.hpp
src/internal/storage_backend_serialized.cpp

index 7afb1f7..022c8d5 100644 (file)
@@ -508,7 +508,7 @@ public:
                                                [](const auto *elem) { return static_cast<id_t>(elem->getId()); });
        }
 
-       auto containerLookupByKey(const List<NameScoresPair> *container, const char *key) const {
+       auto containerLookupByKey(const List<NameScoresPair> *container, boost::string_ref key) const {
                return containerLookupByKey(container, key,
                                                [](const auto *elem) { return elem->getName()->toStringRef(); });
        }
index 53d76dc..5509e55 100644 (file)
@@ -209,16 +209,11 @@ inline ldp_xml_parser::DecisionItem StorageBackendSerialized::getDecisionItem(co
        };
 
        auto searchAndUpdateCurrentBest = [&currentBest, &index, &updateCurrentBest, this](boost::string_ref name_ref) {
-               // we need to create C-string for the lookups
-               // boost::string_ref gives us correct start, but possibly NUL-terminated in a wrong place, as it does not modify
-               // input string and keeps only the length
-               std::string name(name_ref.data(), name_ref.size());
-
                if (impl.containerEmpty(index))
                        return;
 
                // check if there are any rules for the name
-               auto fit = impl.containerLookupByKey(index, name.c_str());
+               auto fit = impl.containerLookupByKey(index, name_ref);
                if (!fit.first)
                        return;