*: use transparent comparison for std::{map,set} with std::string keys

This avoids many std::string temporaries for lookups.
This commit is contained in:
Max Kellermann 2023-03-12 09:11:45 +01:00
parent 27d3dcf14c
commit 8b77da545d
23 changed files with 34 additions and 34 deletions

View File

@ -33,7 +33,7 @@ static constexpr struct {
{ nullptr, 0 },
};
static std::map<std::string, unsigned> permission_passwords;
static std::map<std::string, unsigned, std::less<>> permission_passwords;
static unsigned permission_default;
@ -42,7 +42,7 @@ static unsigned local_permissions;
#endif
#ifdef HAVE_TCP
static std::map<std::string, unsigned> host_passwords;
static std::map<std::string, unsigned, std::less<>> host_passwords;
#endif
static unsigned

View File

@ -88,7 +88,7 @@ private:
/**
* A list of channel names this client is subscribed to.
*/
std::set<std::string> subscriptions;
std::set<std::string, std::less<>> subscriptions;
/**
* The number of subscriptions in #subscriptions. Used to

View File

@ -61,7 +61,7 @@ handle_channels(Client &client, [[maybe_unused]] Request args, Response &r)
{
assert(args.empty());
std::set<std::string> channels;
std::set<std::string, std::less<>> channels;
for (const auto &c : client.GetPartition().clients) {
const auto &subscriptions = c.GetSubscriptions();

View File

@ -24,7 +24,7 @@ struct SearchStats {
: total_duration(0) {}
};
class TagCountMap : public std::map<std::string, SearchStats> {
class TagCountMap : public std::map<std::string, SearchStats, std::less<>> {
};
static void

View File

@ -38,7 +38,7 @@ struct DecoderPlugin {
/**
* Return a set of supported protocols.
*/
std::set<std::string> (*protocols)() noexcept = nullptr;
std::set<std::string, std::less<>> (*protocols)() noexcept = nullptr;
/**
* Decode an URI with a protocol listed in protocols().
@ -138,7 +138,7 @@ struct DecoderPlugin {
return copy;
}
constexpr auto WithProtocols(std::set<std::string> (*_protocols)() noexcept,
constexpr auto WithProtocols(std::set<std::string, std::less<>> (*_protocols)() noexcept,
void (*_uri_decode)(DecoderClient &client, const char *uri)) const noexcept {
auto copy = *this;
copy.protocols = _protocols;

View File

@ -672,10 +672,10 @@ ffmpeg_uri_decode(DecoderClient &client, const char *uri)
FfmpegDecode(client, nullptr, *format_context);
}
static std::set<std::string>
static std::set<std::string, std::less<>>
ffmpeg_protocols() noexcept
{
std::set<std::string> protocols;
std::set<std::string, std::less<>> protocols;
const AVInputFormat *format = nullptr;
void *opaque = nullptr;

View File

@ -52,7 +52,7 @@ struct InputPlugin {
/**
* return a set of supported protocols
*/
std::set<std::string> (*protocols)() noexcept;
std::set<std::string, std::less<>> (*protocols)() noexcept;
/**
* Prepare a #RemoteTagScanner. The operation must be started

View File

@ -589,10 +589,10 @@ input_curl_open(const char *url, Mutex &mutex)
return CurlInputStream::Open(url, {}, mutex);
}
static std::set<std::string>
static std::set<std::string, std::less<>>
input_curl_protocols() noexcept
{
std::set<std::string> protocols;
std::set<std::string, std::less<>> protocols;
auto version_info = curl_version_info(CURLVERSION_FIRST);
for (auto proto_ptr = version_info->protocols; *proto_ptr != nullptr; proto_ptr++) {
if (protocol_is_whitelisted(*proto_ptr)) {

View File

@ -57,12 +57,12 @@ input_ffmpeg_init(EventLoop &, const ConfigBlock &)
throw PluginUnavailable("No protocol");
}
static std::set<std::string>
static std::set<std::string, std::less<>>
input_ffmpeg_protocols() noexcept
{
void *opaque = nullptr;
const char* protocol;
std::set<std::string> protocols;
std::set<std::string, std::less<>> protocols;
while ((protocol = avio_enum_protocols(&opaque, 0))) {
if (StringIsEqual(protocol, "hls")) {
/* just "hls://" doesn't work, but these do

View File

@ -20,7 +20,7 @@ void print_supported_uri_schemes_to_fp(FILE *fp)
#ifdef HAVE_UN
fprintf(fp, " file://");
#endif
std::set<std::string> protocols;
std::set<std::string, std::less<>> protocols;
input_plugins_for_each(plugin)
plugin->ForeachSupportedUri([&](const char* uri) {
protocols.emplace(uri);
@ -40,7 +40,7 @@ void print_supported_uri_schemes_to_fp(FILE *fp)
void
print_supported_uri_schemes(Response &r)
{
std::set<std::string> protocols;
std::set<std::string, std::less<>> protocols;
input_plugins_for_each_enabled(plugin)
plugin->ForeachSupportedUri([&](const char* uri) {
protocols.emplace(uri);

View File

@ -51,9 +51,9 @@ class UdisksNeighborExplorer final
*/
mutable Mutex mutex;
using ByUri = std::map<std::string, NeighborInfo>;
using ByUri = std::map<std::string, NeighborInfo, std::less<>>;
ByUri by_uri;
std::map<std::string, ByUri::iterator> by_path;
std::map<std::string, ByUri::iterator, std::less<>> by_path;
public:
UdisksNeighborExplorer(EventLoop &_event_loop,

View File

@ -103,12 +103,12 @@ AudioOutputControl::GetMixer() const noexcept
return output ? output->mixer : nullptr;
}
std::map<std::string, std::string>
std::map<std::string, std::string, std::less<>>
AudioOutputControl::GetAttributes() const noexcept
{
return output
? output->GetAttributes()
: std::map<std::string, std::string>{};
: std::map<std::string, std::string, std::less<>>{};
}
void

View File

@ -371,7 +371,7 @@ public:
void BeginDestroy() noexcept;
std::map<std::string, std::string> GetAttributes() const noexcept;
std::map<std::string, std::string, std::less<>> GetAttributes() const noexcept;
void SetAttribute(std::string &&name, std::string &&value);
/**

View File

@ -33,7 +33,7 @@ FilteredAudioOutput::SupportsPause() const noexcept
return output->SupportsPause();
}
std::map<std::string, std::string>
std::map<std::string, std::string, std::less<>>
FilteredAudioOutput::GetAttributes() const noexcept
{
return output->GetAttributes();

View File

@ -155,7 +155,7 @@ public:
[[gnu::pure]]
bool SupportsPause() const noexcept;
std::map<std::string, std::string> GetAttributes() const noexcept;
std::map<std::string, std::string, std::less<>> GetAttributes() const noexcept;
void SetAttribute(std::string &&name, std::string &&value);
/**

View File

@ -49,7 +49,7 @@ public:
*
* This method must be thread-safe.
*/
virtual std::map<std::string, std::string> GetAttributes() const noexcept {
virtual std::map<std::string, std::string, std::less<>> GetAttributes() const noexcept {
return {};
}

View File

@ -257,7 +257,7 @@ public:
}
private:
std::map<std::string, std::string> GetAttributes() const noexcept override;
std::map<std::string, std::string, std::less<>> GetAttributes() const noexcept override;
void SetAttribute(std::string &&name, std::string &&value) override;
void Enable() override;
@ -444,7 +444,7 @@ AlsaOutput::AlsaOutput(EventLoop &_loop, const ConfigBlock &block)
allowed_formats = Alsa::AllowedFormat::ParseList(allowed_formats_string);
}
std::map<std::string, std::string>
std::map<std::string, std::string, std::less<>>
AlsaOutput::GetAttributes() const noexcept
{
const std::scoped_lock<Mutex> lock(attributes_mutex);

View File

@ -129,7 +129,7 @@ StickerDatabase::LoadValue(const char *type, const char *uri, const char *name)
}
void
StickerDatabase::ListValues(std::map<std::string, std::string> &table,
StickerDatabase::ListValues(std::map<std::string, std::string, std::less<>> &table,
const char *type, const char *uri)
{
sqlite3_stmt *const s = stmt[STICKER_SQL_LIST];

View File

@ -127,7 +127,7 @@ public:
void *user_data);
private:
void ListValues(std::map<std::string, std::string> &table,
void ListValues(std::map<std::string, std::string, std::less<>> &table,
const char *type, const char *uri);
bool UpdateValue(const char *type, const char *uri,

View File

@ -8,7 +8,7 @@
#include <string>
struct Sticker {
std::map<std::string, std::string> table;
std::map<std::string, std::string, std::less<>> table;
};
#endif

View File

@ -20,8 +20,8 @@
class CompositeDirectoryReader final : public StorageDirectoryReader {
std::unique_ptr<StorageDirectoryReader> other;
std::set<std::string> names;
std::set<std::string>::const_iterator current, next;
std::set<std::string, std::less<>> names;
std::set<std::string, std::less<>>::const_iterator current, next;
public:
template<typename O, typename M>

View File

@ -12,13 +12,13 @@ GetMimeTypeBase(std::string_view s) noexcept
return Split(s, ';').first;
}
std::map<std::string, std::string>
std::map<std::string, std::string, std::less<>>
ParseMimeTypeParameters(std::string_view mime_type) noexcept
{
/* discard the first segment (the base MIME type) */
const auto params = Split(mime_type, ';').second;
std::map<std::string, std::string> result;
std::map<std::string, std::string, std::less<>> result;
for (const std::string_view i : IterableSplitString(params, ';')) {
const auto s = Split(Strip(i), '=');
if (!s.first.empty() && s.second.data() != nullptr)

View File

@ -23,7 +23,7 @@ GetMimeTypeBase(std::string_view s) noexcept;
*
* "foo/bar; param1=value1; param2=value2"
*/
std::map<std::string, std::string>
std::map<std::string, std::string, std::less<>>
ParseMimeTypeParameters(std::string_view mime_type) noexcept;
#endif