diff options
author | Rosen Penev <rosenp@gmail.com> | 2020-10-22 01:36:13 -0700 |
---|---|---|
committer | Rosen Penev <rosenp@gmail.com> | 2020-10-28 15:41:31 -0700 |
commit | 0fd2c74a66fea893496d25561fd56b5ad5c45090 (patch) | |
tree | 4a8f093095d540032e82c95198912648878688c5 | |
parent | bb99cf37e3f48c851bea671566cd9923d771396d (diff) |
use structured binding declarations
Shorter.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
-rw-r--r-- | src/RemoteTagCache.cxx | 14 | ||||
-rw-r--r-- | src/client/Subscribe.cxx | 3 | ||||
-rw-r--r-- | src/db/Count.cxx | 12 | ||||
-rw-r--r-- | src/db/DatabasePrint.cxx | 6 | ||||
-rw-r--r-- | src/db/plugins/simple/Directory.cxx | 7 | ||||
-rw-r--r-- | src/db/update/Walk.cxx | 8 | ||||
-rw-r--r-- | src/event/WinSelectBackend.cxx | 8 | ||||
-rw-r--r-- | src/input/plugins/CurlInputPlugin.cxx | 4 | ||||
-rw-r--r-- | src/input/plugins/QobuzClient.cxx | 12 | ||||
-rw-r--r-- | src/lib/curl/Form.cxx | 10 | ||||
-rw-r--r-- | src/neighbor/plugins/UdisksNeighborPlugin.cxx | 4 | ||||
-rw-r--r-- | src/output/Print.cxx | 5 | ||||
-rw-r--r-- | src/output/plugins/WasapiOutputPlugin.cxx | 8 | ||||
-rw-r--r-- | src/sticker/Print.cxx | 4 | ||||
-rw-r--r-- | src/tag/GenParseName.cxx | 5 |
15 files changed, 49 insertions, 61 deletions
diff --git a/src/RemoteTagCache.cxx b/src/RemoteTagCache.cxx index 3377a5831..facf6300d 100644 --- a/src/RemoteTagCache.cxx +++ b/src/RemoteTagCache.cxx @@ -42,9 +42,9 @@ RemoteTagCache::Lookup(const std::string &uri) noexcept std::unique_lock<Mutex> lock(mutex); KeyMap::insert_commit_data hint; - auto result = map.insert_check(uri, Item::Hash(), Item::Equal(), hint); - if (result.second) { - auto *item = new Item(*this, uri); + auto [tag, value] = map.insert_check(uri, Item::Hash(), Item::Equal(), hint); + if (value) { + auto item = new Item(*this, uri); map.insert_commit(*item, hint); waiting_list.push_back(*item); lock.unlock(); @@ -70,15 +70,13 @@ RemoteTagCache::Lookup(const std::string &uri) noexcept ItemResolved(*item); return; } - } else if (result.first->scanner) { + } else if (tag->scanner) { /* already scanning this one - no-op */ } else { /* already finished: re-invoke the handler */ - auto &item = *result.first; - - idle_list.erase(waiting_list.iterator_to(item)); - invoke_list.push_back(item); + idle_list.erase(waiting_list.iterator_to(*tag)); + invoke_list.push_back(*tag); ScheduleInvokeHandlers(); } diff --git a/src/client/Subscribe.cxx b/src/client/Subscribe.cxx index 0b65d5b1b..dcfa81408 100644 --- a/src/client/Subscribe.cxx +++ b/src/client/Subscribe.cxx @@ -34,8 +34,7 @@ Client::Subscribe(const char *channel) noexcept if (num_subscriptions >= MAX_SUBSCRIPTIONS) return Client::SubscribeResult::FULL; - auto r = subscriptions.insert(channel); - if (!r.second) + if (!subscriptions.insert(channel).second) return Client::SubscribeResult::ALREADY; ++num_subscriptions; diff --git a/src/db/Count.cxx b/src/db/Count.cxx index 68ee99c11..2df72e1e1 100644 --- a/src/db/Count.cxx +++ b/src/db/Count.cxx @@ -57,9 +57,9 @@ Print(Response &r, TagType group, const TagCountMap &m) noexcept { assert(unsigned(group) < TAG_NUM_OF_ITEM_TYPES); - for (const auto &i : m) { - tag_print(r, group, i.first.c_str()); - PrintSearchStats(r, i.second); + for (const auto &[tag, stats] : m) { + tag_print(r, group, tag.c_str()); + PrintSearchStats(r, stats); } } @@ -68,8 +68,7 @@ stats_visitor_song(SearchStats &stats, const LightSong &song) noexcept { stats.n_songs++; - const auto duration = song.GetDuration(); - if (!duration.IsNegative()) + if (const auto duration = song.GetDuration(); !duration.IsNegative()) stats.total_duration += duration; } @@ -77,8 +76,7 @@ static void CollectGroupCounts(TagCountMap &map, const Tag &tag, const char *value) noexcept { - auto r = map.insert(std::make_pair(value, SearchStats())); - SearchStats &s = r.first->second; + auto &s = map.insert(std::make_pair(value, SearchStats())).first->second; ++s.n_songs; if (!tag.duration.IsNegative()) s.total_duration += tag.duration; diff --git a/src/db/DatabasePrint.cxx b/src/db/DatabasePrint.cxx index b4d9315a2..a5fae49fe 100644 --- a/src/db/DatabasePrint.cxx +++ b/src/db/DatabasePrint.cxx @@ -195,11 +195,11 @@ PrintUniqueTags(Response &r, ConstBuffer<TagType> tag_types, const char *const name = tag_item_names[tag_types.front()]; tag_types.pop_front(); - for (const auto &i : map) { - r.Format("%s: %s\n", name, i.first.c_str()); + for (const auto &[key, tag] : map) { + r.Format("%s: %s\n", name, key.c_str()); if (!tag_types.empty()) - PrintUniqueTags(r, tag_types, i.second); + PrintUniqueTags(r, tag_types, tag); } } diff --git a/src/db/plugins/simple/Directory.cxx b/src/db/plugins/simple/Directory.cxx index e78b6e6fb..8710b4f1c 100644 --- a/src/db/plugins/simple/Directory.cxx +++ b/src/db/plugins/simple/Directory.cxx @@ -138,13 +138,10 @@ Directory::LookupDirectory(std::string_view _uri) noexcept Directory *d = this; do { - auto s = uri.Split(PathTraitsUTF8::SEPARATOR); - if (s.first.empty()) + auto [name, rest] = uri.Split(PathTraitsUTF8::SEPARATOR); + if (name.empty()) break; - const auto name = s.first; - const auto rest = s.second; - Directory *tmp = d->FindChild(name); if (tmp == nullptr) /* not found */ diff --git a/src/db/update/Walk.cxx b/src/db/update/Walk.cxx index 3e0677e91..43366067a 100644 --- a/src/db/update/Walk.cxx +++ b/src/db/update/Walk.cxx @@ -427,21 +427,19 @@ UpdateWalk::DirectoryMakeUriParentChecked(Directory &root, StringView uri(_uri); while (true) { - auto s = uri.Split('/'); - const std::string_view name = s.first; - const auto rest = s.second; + auto [name, rest] = uri.Split('/'); if (rest == nullptr) break; if (!name.empty()) { directory = DirectoryMakeChildChecked(*directory, std::string(name).c_str(), - s.first); + name); if (directory == nullptr) break; } - uri = s.second; + uri = rest; } return directory; diff --git a/src/event/WinSelectBackend.cxx b/src/event/WinSelectBackend.cxx index e8d7ab12d..67a574992 100644 --- a/src/event/WinSelectBackend.cxx +++ b/src/event/WinSelectBackend.cxx @@ -156,10 +156,10 @@ WinSelectBackend::ReadEvents(int timeout_ms) noexcept for (const auto i : except_set) items[i].events |= WinSelectEvents::WRITE; - for (auto &i : items) - if (i.second.events != 0) { - result.Add(i.second.events, i.second.obj); - i.second.events = 0; + for (auto &[key, item] : items) + if (item.events != 0) { + result.Add(item.events, item.obj); + item.events = 0; } return result; diff --git a/src/input/plugins/CurlInputPlugin.cxx b/src/input/plugins/CurlInputPlugin.cxx index 3cdab5653..057f7cd9b 100644 --- a/src/input/plugins/CurlInputPlugin.cxx +++ b/src/input/plugins/CurlInputPlugin.cxx @@ -395,8 +395,8 @@ CurlInputStream::CurlInputStream(EventLoop &event_loop, const char *_url, { request_headers.Append("Icy-Metadata: 1"); - for (const auto &i : headers) - request_headers.Append((i.first + ":" + i.second).c_str()); + for (const auto &[key, header] : headers) + request_headers.Append((key + ":" + header).c_str()); } CurlInputStream::~CurlInputStream() noexcept diff --git a/src/input/plugins/QobuzClient.cxx b/src/input/plugins/QobuzClient.cxx index bfffd863a..7655737f7 100644 --- a/src/input/plugins/QobuzClient.cxx +++ b/src/input/plugins/QobuzClient.cxx @@ -174,8 +174,8 @@ QobuzClient::MakeUrl(const char *object, const char *method, uri += method; QueryStringBuilder q; - for (const auto &i : query) - q(uri, i.first.c_str(), i.second.c_str()); + for (const auto &[key, url] : query) + q(uri, key.c_str(), url.c_str()); q(uri, "app_id", app_id); return uri; @@ -195,11 +195,11 @@ QobuzClient::MakeSignedUrl(const char *object, const char *method, QueryStringBuilder q; std::string concatenated_query(object); concatenated_query += method; - for (const auto &i : query) { - q(uri, i.first.c_str(), i.second.c_str()); + for (const auto &[key, url] : query) { + q(uri, key.c_str(), url.c_str()); - concatenated_query += i.first; - concatenated_query += i.second; + concatenated_query += key; + concatenated_query += url; } q(uri, "app_id", app_id); diff --git a/src/lib/curl/Form.cxx b/src/lib/curl/Form.cxx index 65430641d..5b668ec46 100644 --- a/src/lib/curl/Form.cxx +++ b/src/lib/curl/Form.cxx @@ -36,16 +36,16 @@ EncodeForm(CURL *curl, { std::string result; - for (const auto &i : fields) { + for (const auto &[key, field] : fields) { if (!result.empty()) result.push_back('&'); - result.append(i.first); + result.append(key); result.push_back('='); - if (!i.second.empty()) { - CurlString value(curl_easy_escape(curl, i.second.data(), - i.second.length())); + if (!field.empty()) { + CurlString value( + curl_easy_escape(curl, field.data(), field.length())); if (value) result.append(value); } diff --git a/src/neighbor/plugins/UdisksNeighborPlugin.cxx b/src/neighbor/plugins/UdisksNeighborPlugin.cxx index 687fff0e2..6d683a731 100644 --- a/src/neighbor/plugins/UdisksNeighborPlugin.cxx +++ b/src/neighbor/plugins/UdisksNeighborPlugin.cxx @@ -182,8 +182,8 @@ UdisksNeighborExplorer::GetList() const noexcept NeighborExplorer::List result; - for (const auto &i : by_uri) - result.emplace_front(i.second); + for (const auto &[t, r] : by_uri) + result.emplace_front(r); return result; } diff --git a/src/output/Print.cxx b/src/output/Print.cxx index 9f0b0ddc9..d05198710 100644 --- a/src/output/Print.cxx +++ b/src/output/Print.cxx @@ -40,8 +40,7 @@ printAudioDevices(Response &r, const MultipleOutputs &outputs) ao.GetName(), ao.GetPluginName(), ao.IsEnabled()); - for (const auto &a : ao.GetAttributes()) - r.Format("attribute: %s=%s\n", - a.first.c_str(), a.second.c_str()); + for (const auto &[attribute, value] : ao.GetAttributes()) + r.Format("attribute: %s=%s\n", attribute.c_str(), value.c_str()); } } diff --git a/src/output/plugins/WasapiOutputPlugin.cxx b/src/output/plugins/WasapiOutputPlugin.cxx index 94fa1e647..97ddccd30 100644 --- a/src/output/plugins/WasapiOutputPlugin.cxx +++ b/src/output/plugins/WasapiOutputPlugin.cxx @@ -321,9 +321,11 @@ void WasapiOutput::Enable() { device.reset(); if (enumerate_devices && SafeTry([this]() { EnumerateDevices(); })) { - for (const auto &desc : device_desc) { - FormatNotice(wasapi_output_domain, "Device \"%u\" \"%s\"", - desc.first, desc.second.c_str()); + for (const auto &[device, desc] : device_desc) { + FormatNotice(wasapi_output_domain, + "Device \"%u\" \"%s\"", + device, + desc.c_str()); } } diff --git a/src/sticker/Print.cxx b/src/sticker/Print.cxx index 3c3a9602b..5a558864c 100644 --- a/src/sticker/Print.cxx +++ b/src/sticker/Print.cxx @@ -31,6 +31,6 @@ sticker_print_value(Response &r, void sticker_print(Response &r, const Sticker &sticker) { - for (const auto &i : sticker.table) - sticker_print_value(r, i.first.c_str(), i.second.c_str()); + for (const auto &[name, val] : sticker.table) + sticker_print_value(r, name.c_str(), val.c_str()); } diff --git a/src/tag/GenParseName.cxx b/src/tag/GenParseName.cxx index 70bbf7c39..4582162b2 100644 --- a/src/tag/GenParseName.cxx +++ b/src/tag/GenParseName.cxx @@ -60,10 +60,7 @@ main(int argc, char **argv) char first = 0; - for (const auto &i : names) { - const std::string_view name = i.first; - const TagType tag = i.second; - + for (const auto &[name, tag] : names) { if (name.front() != first) { if (first != 0) fprintf(out, " break;\n\n"); |