]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
refactor: Simplify Redis URL parameter parsing
authorJoel Rosdahl <joel@rosdahl.net>
Thu, 7 Jul 2022 10:31:58 +0000 (12:31 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Thu, 7 Jul 2022 13:17:18 +0000 (15:17 +0200)
src/storage/secondary/RedisStorage.cpp

index 976386a7f233c93eb1ec0da5b84a214395474e73..4c98634e3c5e7549817581677ea2dd0a2a7165dd 100644 (file)
@@ -106,20 +106,6 @@ split_user_info(const std::string& user_info)
   }
 }
 
-std::map<std::string, std::string>
-split_parameters(const Url::Query& query)
-{
-  std::map<std::string, std::string> m;
-  if (!query.empty()) {
-    auto it = query.begin();
-    auto end = query.end();
-    do {
-      m[it->key()] = it->val();
-    } while (++it != end);
-  }
-  return m;
-}
-
 RedisStorageBackend::RedisStorageBackend(const Params& params)
   : m_prefix("ccache"), // TODO: attribute
     m_context(nullptr, redisFree)
@@ -289,15 +275,14 @@ RedisStorageBackend::select_database(const Url& url)
 {
   std::optional<std::string> db;
   if (url.scheme() == "redis+unix") {
-    const auto parameters_map = split_parameters(url.query());
-    auto search = parameters_map.find("db");
-    if (search != parameters_map.end()) {
-      db = search->second;
-    }
-  } else {
-    if (!url.path().empty()) {
-      db = url.path().substr(1);
+    for (const auto& param : url.query()) {
+      if (param.key() == "db") {
+        db = param.val();
+        break;
+      }
     }
+  } else if (!url.path().empty()) {
+    db = url.path().substr(1);
   }
   const uint32_t db_number =
     !db ? 0