summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Szyndela <adrian.s@samsung.com>2020-12-11 10:06:16 +0100
committerAdrian Szyndela <adrian.s@samsung.com>2020-12-11 10:11:10 +0100
commit7e357b033baac41efed09a4a021ca113b1c280d8 (patch)
treee8cbb3edb30ff9fafb515ac5f43fdc6cf9bedf80
parentc97b4b2fc2282f2754e99bc70d00f0b194bbde30 (diff)
downloadlibdbuspolicy-7e357b033baac41efed09a4a021ca113b1c280d8.tar.gz
libdbuspolicy-7e357b033baac41efed09a4a021ca113b1c280d8.tar.bz2
libdbuspolicy-7e357b033baac41efed09a4a021ca113b1c280d8.zip
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
-rw-r--r--src/internal/storage_backend_direct.hpp2
-rw-r--r--src/internal/storage_backend_serialized.cpp7
2 files changed, 2 insertions, 7 deletions
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<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(); });
}
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 = [&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;