settings: const-correctness and simplify prefix search

Cursor is in a weird spot, by being both the pointer to the data and the
read-range that is used of specify the range in which we operate
Next TODO would be to move even more things to 'const', but that would
at least require to rework the cursor object and also remove it from the
members list.
This commit is contained in:
Maxim Prokhorov
2022-02-09 14:39:55 +03:00
parent 9501595a16
commit 1a4926da2d
4 changed files with 79 additions and 48 deletions

View File

@@ -36,15 +36,9 @@ namespace {
void deletePrefixes(::settings::query::StringViewIterator prefixes) {
std::vector<String> to_purge;
::settings::internal::foreach([&](::settings::kvs_type::KeyValueResult&& kv) {
const auto key = kv.key.read();
for (auto it = prefixes.begin(); it != prefixes.end(); ++it) {
if (::settings::query::samePrefix(::settings::StringView{key}, (*it))) {
to_purge.push_back(std::move(key));
return;
}
}
});
::settings::internal::foreach_prefix([&](::settings::StringView, String key, const ::settings::kvs_type::ReadResult&) {
to_purge.push_back(std::move(key));
}, prefixes);
for (const auto& key : to_purge) {
delSetting(key);