From: Adrian Szyndela Date: Fri, 11 Dec 2020 09:06:16 +0000 (+0100) Subject: serialized: don't copy strings in policy lookups X-Git-Tag: accepted/tizen/unified/20201214.124456~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7e357b033baac41efed09a4a021ca113b1c280d8;p=platform%2Fcore%2Fsystem%2Flibdbuspolicy.git serialized: don't copy strings in policy lookups 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 --- diff --git a/src/internal/storage_backend_direct.hpp b/src/internal/storage_backend_direct.hpp index 7afb1f7..022c8d5 100644 --- a/src/internal/storage_backend_direct.hpp +++ b/src/internal/storage_backend_direct.hpp @@ -508,7 +508,7 @@ public: [](const auto *elem) { return static_cast(elem->getId()); }); } - auto containerLookupByKey(const List *container, const char *key) const { + auto containerLookupByKey(const List *container, boost::string_ref key) const { return containerLookupByKey(container, key, [](const auto *elem) { return elem->getName()->toStringRef(); }); } diff --git a/src/internal/storage_backend_serialized.cpp b/src/internal/storage_backend_serialized.cpp index 53d76dc..5509e55 100644 --- a/src/internal/storage_backend_serialized.cpp +++ b/src/internal/storage_backend_serialized.cpp @@ -209,16 +209,11 @@ inline ldp_xml_parser::DecisionItem StorageBackendSerialized::getDecisionItem(co }; auto searchAndUpdateCurrentBest = [¤tBest, &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;