aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-01-03 02:40:21 +0100
committerMax Kellermann <max@duempel.org>2013-01-03 02:40:21 +0100
commita2297558ff6162f1669e7982ba406c44b01b0c79 (patch)
tree6247e34ee45d9291059e824676e51668ddb73424 /src
parent84cdf0caccf7b61e60e5f8f716f54f8ed6d23dae (diff)
downloadmpd-a2297558ff6162f1669e7982ba406c44b01b0c79.tar.gz
mpd-a2297558ff6162f1669e7982ba406c44b01b0c79.tar.xz
mpd-a2297558ff6162f1669e7982ba406c44b01b0c79.zip
MessageCommands: use std::set instead of GHashTable
Diffstat (limited to 'src')
-rw-r--r--src/MessageCommands.cxx34
1 files changed, 8 insertions, 26 deletions
diff --git a/src/MessageCommands.cxx b/src/MessageCommands.cxx
index 428470e60..c8ced1f35 100644
--- a/src/MessageCommands.cxx
+++ b/src/MessageCommands.cxx
@@ -27,6 +27,9 @@ extern "C" {
#include "client_subscribe.h"
}
+#include <set>
+#include <string>
+
#include <assert.h>
enum command_return
@@ -73,9 +76,7 @@ handle_unsubscribe(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
}
struct channels_context {
- GStringChunk *chunk;
-
- GHashTable *channels;
+ std::set<std::string> channels;
};
static void
@@ -89,41 +90,22 @@ collect_channels(gpointer data, gpointer user_data)
i = g_slist_next(i)) {
const char *channel = (const char *)i->data;
- if (g_hash_table_lookup(context->channels, channel) == NULL) {
- char *channel2 = g_string_chunk_insert(context->chunk,
- channel);
- g_hash_table_insert(context->channels, channel2,
- context);
- }
+ context->channels.insert(channel);
}
}
-static void
-print_channel(gpointer key, G_GNUC_UNUSED gpointer value, gpointer user_data)
-{
- struct client *client = (struct client *)user_data;
- const char *channel = (const char *)key;
-
- client_printf(client, "channel: %s\n", channel);
-}
-
enum command_return
handle_channels(struct client *client,
G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[])
{
assert(argc == 1);
- struct channels_context context = {
- g_string_chunk_new(1024),
- g_hash_table_new(g_str_hash, g_str_equal),
- };
+ struct channels_context context;
client_list_foreach(collect_channels, &context);
- g_hash_table_foreach(context.channels, print_channel, client);
-
- g_hash_table_destroy(context.channels);
- g_string_chunk_free(context.chunk);
+ for (const auto &channel : context.channels)
+ client_printf(client, "channel: %s\n", channel.c_str());
return COMMAND_RETURN_OK;
}