use structured binding declarations
Shorter. Signed-off-by: Rosen Penev <rosenp@gmail.com>
This commit is contained in:
parent
bb99cf37e3
commit
0fd2c74a66
|
@ -42,9 +42,9 @@ RemoteTagCache::Lookup(const std::string &uri) noexcept
|
||||||
std::unique_lock<Mutex> lock(mutex);
|
std::unique_lock<Mutex> lock(mutex);
|
||||||
|
|
||||||
KeyMap::insert_commit_data hint;
|
KeyMap::insert_commit_data hint;
|
||||||
auto result = map.insert_check(uri, Item::Hash(), Item::Equal(), hint);
|
auto [tag, value] = map.insert_check(uri, Item::Hash(), Item::Equal(), hint);
|
||||||
if (result.second) {
|
if (value) {
|
||||||
auto *item = new Item(*this, uri);
|
auto item = new Item(*this, uri);
|
||||||
map.insert_commit(*item, hint);
|
map.insert_commit(*item, hint);
|
||||||
waiting_list.push_back(*item);
|
waiting_list.push_back(*item);
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
|
@ -70,15 +70,13 @@ RemoteTagCache::Lookup(const std::string &uri) noexcept
|
||||||
ItemResolved(*item);
|
ItemResolved(*item);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if (result.first->scanner) {
|
} else if (tag->scanner) {
|
||||||
/* already scanning this one - no-op */
|
/* already scanning this one - no-op */
|
||||||
} else {
|
} else {
|
||||||
/* already finished: re-invoke the handler */
|
/* already finished: re-invoke the handler */
|
||||||
|
|
||||||
auto &item = *result.first;
|
idle_list.erase(waiting_list.iterator_to(*tag));
|
||||||
|
invoke_list.push_back(*tag);
|
||||||
idle_list.erase(waiting_list.iterator_to(item));
|
|
||||||
invoke_list.push_back(item);
|
|
||||||
|
|
||||||
ScheduleInvokeHandlers();
|
ScheduleInvokeHandlers();
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,8 +34,7 @@ Client::Subscribe(const char *channel) noexcept
|
||||||
if (num_subscriptions >= MAX_SUBSCRIPTIONS)
|
if (num_subscriptions >= MAX_SUBSCRIPTIONS)
|
||||||
return Client::SubscribeResult::FULL;
|
return Client::SubscribeResult::FULL;
|
||||||
|
|
||||||
auto r = subscriptions.insert(channel);
|
if (!subscriptions.insert(channel).second)
|
||||||
if (!r.second)
|
|
||||||
return Client::SubscribeResult::ALREADY;
|
return Client::SubscribeResult::ALREADY;
|
||||||
|
|
||||||
++num_subscriptions;
|
++num_subscriptions;
|
||||||
|
|
|
@ -57,9 +57,9 @@ Print(Response &r, TagType group, const TagCountMap &m) noexcept
|
||||||
{
|
{
|
||||||
assert(unsigned(group) < TAG_NUM_OF_ITEM_TYPES);
|
assert(unsigned(group) < TAG_NUM_OF_ITEM_TYPES);
|
||||||
|
|
||||||
for (const auto &i : m) {
|
for (const auto &[tag, stats] : m) {
|
||||||
tag_print(r, group, i.first.c_str());
|
tag_print(r, group, tag.c_str());
|
||||||
PrintSearchStats(r, i.second);
|
PrintSearchStats(r, stats);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,8 +68,7 @@ stats_visitor_song(SearchStats &stats, const LightSong &song) noexcept
|
||||||
{
|
{
|
||||||
stats.n_songs++;
|
stats.n_songs++;
|
||||||
|
|
||||||
const auto duration = song.GetDuration();
|
if (const auto duration = song.GetDuration(); !duration.IsNegative())
|
||||||
if (!duration.IsNegative())
|
|
||||||
stats.total_duration += duration;
|
stats.total_duration += duration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,8 +76,7 @@ static void
|
||||||
CollectGroupCounts(TagCountMap &map, const Tag &tag,
|
CollectGroupCounts(TagCountMap &map, const Tag &tag,
|
||||||
const char *value) noexcept
|
const char *value) noexcept
|
||||||
{
|
{
|
||||||
auto r = map.insert(std::make_pair(value, SearchStats()));
|
auto &s = map.insert(std::make_pair(value, SearchStats())).first->second;
|
||||||
SearchStats &s = r.first->second;
|
|
||||||
++s.n_songs;
|
++s.n_songs;
|
||||||
if (!tag.duration.IsNegative())
|
if (!tag.duration.IsNegative())
|
||||||
s.total_duration += tag.duration;
|
s.total_duration += tag.duration;
|
||||||
|
|
|
@ -195,11 +195,11 @@ PrintUniqueTags(Response &r, ConstBuffer<TagType> tag_types,
|
||||||
const char *const name = tag_item_names[tag_types.front()];
|
const char *const name = tag_item_names[tag_types.front()];
|
||||||
tag_types.pop_front();
|
tag_types.pop_front();
|
||||||
|
|
||||||
for (const auto &i : map) {
|
for (const auto &[key, tag] : map) {
|
||||||
r.Format("%s: %s\n", name, i.first.c_str());
|
r.Format("%s: %s\n", name, key.c_str());
|
||||||
|
|
||||||
if (!tag_types.empty())
|
if (!tag_types.empty())
|
||||||
PrintUniqueTags(r, tag_types, i.second);
|
PrintUniqueTags(r, tag_types, tag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -138,13 +138,10 @@ Directory::LookupDirectory(std::string_view _uri) noexcept
|
||||||
|
|
||||||
Directory *d = this;
|
Directory *d = this;
|
||||||
do {
|
do {
|
||||||
auto s = uri.Split(PathTraitsUTF8::SEPARATOR);
|
auto [name, rest] = uri.Split(PathTraitsUTF8::SEPARATOR);
|
||||||
if (s.first.empty())
|
if (name.empty())
|
||||||
break;
|
break;
|
||||||
|
|
||||||
const auto name = s.first;
|
|
||||||
const auto rest = s.second;
|
|
||||||
|
|
||||||
Directory *tmp = d->FindChild(name);
|
Directory *tmp = d->FindChild(name);
|
||||||
if (tmp == nullptr)
|
if (tmp == nullptr)
|
||||||
/* not found */
|
/* not found */
|
||||||
|
|
|
@ -427,21 +427,19 @@ UpdateWalk::DirectoryMakeUriParentChecked(Directory &root,
|
||||||
StringView uri(_uri);
|
StringView uri(_uri);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
auto s = uri.Split('/');
|
auto [name, rest] = uri.Split('/');
|
||||||
const std::string_view name = s.first;
|
|
||||||
const auto rest = s.second;
|
|
||||||
if (rest == nullptr)
|
if (rest == nullptr)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (!name.empty()) {
|
if (!name.empty()) {
|
||||||
directory = DirectoryMakeChildChecked(*directory,
|
directory = DirectoryMakeChildChecked(*directory,
|
||||||
std::string(name).c_str(),
|
std::string(name).c_str(),
|
||||||
s.first);
|
name);
|
||||||
if (directory == nullptr)
|
if (directory == nullptr)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
uri = s.second;
|
uri = rest;
|
||||||
}
|
}
|
||||||
|
|
||||||
return directory;
|
return directory;
|
||||||
|
|
|
@ -156,10 +156,10 @@ WinSelectBackend::ReadEvents(int timeout_ms) noexcept
|
||||||
for (const auto i : except_set)
|
for (const auto i : except_set)
|
||||||
items[i].events |= WinSelectEvents::WRITE;
|
items[i].events |= WinSelectEvents::WRITE;
|
||||||
|
|
||||||
for (auto &i : items)
|
for (auto &[key, item] : items)
|
||||||
if (i.second.events != 0) {
|
if (item.events != 0) {
|
||||||
result.Add(i.second.events, i.second.obj);
|
result.Add(item.events, item.obj);
|
||||||
i.second.events = 0;
|
item.events = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -395,8 +395,8 @@ CurlInputStream::CurlInputStream(EventLoop &event_loop, const char *_url,
|
||||||
{
|
{
|
||||||
request_headers.Append("Icy-Metadata: 1");
|
request_headers.Append("Icy-Metadata: 1");
|
||||||
|
|
||||||
for (const auto &i : headers)
|
for (const auto &[key, header] : headers)
|
||||||
request_headers.Append((i.first + ":" + i.second).c_str());
|
request_headers.Append((key + ":" + header).c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
CurlInputStream::~CurlInputStream() noexcept
|
CurlInputStream::~CurlInputStream() noexcept
|
||||||
|
|
|
@ -174,8 +174,8 @@ QobuzClient::MakeUrl(const char *object, const char *method,
|
||||||
uri += method;
|
uri += method;
|
||||||
|
|
||||||
QueryStringBuilder q;
|
QueryStringBuilder q;
|
||||||
for (const auto &i : query)
|
for (const auto &[key, url] : query)
|
||||||
q(uri, i.first.c_str(), i.second.c_str());
|
q(uri, key.c_str(), url.c_str());
|
||||||
|
|
||||||
q(uri, "app_id", app_id);
|
q(uri, "app_id", app_id);
|
||||||
return uri;
|
return uri;
|
||||||
|
@ -195,11 +195,11 @@ QobuzClient::MakeSignedUrl(const char *object, const char *method,
|
||||||
QueryStringBuilder q;
|
QueryStringBuilder q;
|
||||||
std::string concatenated_query(object);
|
std::string concatenated_query(object);
|
||||||
concatenated_query += method;
|
concatenated_query += method;
|
||||||
for (const auto &i : query) {
|
for (const auto &[key, url] : query) {
|
||||||
q(uri, i.first.c_str(), i.second.c_str());
|
q(uri, key.c_str(), url.c_str());
|
||||||
|
|
||||||
concatenated_query += i.first;
|
concatenated_query += key;
|
||||||
concatenated_query += i.second;
|
concatenated_query += url;
|
||||||
}
|
}
|
||||||
|
|
||||||
q(uri, "app_id", app_id);
|
q(uri, "app_id", app_id);
|
||||||
|
|
|
@ -36,16 +36,16 @@ EncodeForm(CURL *curl,
|
||||||
{
|
{
|
||||||
std::string result;
|
std::string result;
|
||||||
|
|
||||||
for (const auto &i : fields) {
|
for (const auto &[key, field] : fields) {
|
||||||
if (!result.empty())
|
if (!result.empty())
|
||||||
result.push_back('&');
|
result.push_back('&');
|
||||||
|
|
||||||
result.append(i.first);
|
result.append(key);
|
||||||
result.push_back('=');
|
result.push_back('=');
|
||||||
|
|
||||||
if (!i.second.empty()) {
|
if (!field.empty()) {
|
||||||
CurlString value(curl_easy_escape(curl, i.second.data(),
|
CurlString value(
|
||||||
i.second.length()));
|
curl_easy_escape(curl, field.data(), field.length()));
|
||||||
if (value)
|
if (value)
|
||||||
result.append(value);
|
result.append(value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -182,8 +182,8 @@ UdisksNeighborExplorer::GetList() const noexcept
|
||||||
|
|
||||||
NeighborExplorer::List result;
|
NeighborExplorer::List result;
|
||||||
|
|
||||||
for (const auto &i : by_uri)
|
for (const auto &[t, r] : by_uri)
|
||||||
result.emplace_front(i.second);
|
result.emplace_front(r);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,8 +40,7 @@ printAudioDevices(Response &r, const MultipleOutputs &outputs)
|
||||||
ao.GetName(), ao.GetPluginName(),
|
ao.GetName(), ao.GetPluginName(),
|
||||||
ao.IsEnabled());
|
ao.IsEnabled());
|
||||||
|
|
||||||
for (const auto &a : ao.GetAttributes())
|
for (const auto &[attribute, value] : ao.GetAttributes())
|
||||||
r.Format("attribute: %s=%s\n",
|
r.Format("attribute: %s=%s\n", attribute.c_str(), value.c_str());
|
||||||
a.first.c_str(), a.second.c_str());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -321,9 +321,11 @@ void WasapiOutput::Enable() {
|
||||||
device.reset();
|
device.reset();
|
||||||
|
|
||||||
if (enumerate_devices && SafeTry([this]() { EnumerateDevices(); })) {
|
if (enumerate_devices && SafeTry([this]() { EnumerateDevices(); })) {
|
||||||
for (const auto &desc : device_desc) {
|
for (const auto &[device, desc] : device_desc) {
|
||||||
FormatNotice(wasapi_output_domain, "Device \"%u\" \"%s\"",
|
FormatNotice(wasapi_output_domain,
|
||||||
desc.first, desc.second.c_str());
|
"Device \"%u\" \"%s\"",
|
||||||
|
device,
|
||||||
|
desc.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,6 @@ sticker_print_value(Response &r,
|
||||||
void
|
void
|
||||||
sticker_print(Response &r, const Sticker &sticker)
|
sticker_print(Response &r, const Sticker &sticker)
|
||||||
{
|
{
|
||||||
for (const auto &i : sticker.table)
|
for (const auto &[name, val] : sticker.table)
|
||||||
sticker_print_value(r, i.first.c_str(), i.second.c_str());
|
sticker_print_value(r, name.c_str(), val.c_str());
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,10 +60,7 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
char first = 0;
|
char first = 0;
|
||||||
|
|
||||||
for (const auto &i : names) {
|
for (const auto &[name, tag] : names) {
|
||||||
const std::string_view name = i.first;
|
|
||||||
const TagType tag = i.second;
|
|
||||||
|
|
||||||
if (name.front() != first) {
|
if (name.front() != first) {
|
||||||
if (first != 0)
|
if (first != 0)
|
||||||
fprintf(out, " break;\n\n");
|
fprintf(out, " break;\n\n");
|
||||||
|
|
Loading…
Reference in New Issue