aboutsummaryrefslogtreecommitdiff
path: root/src/ClientSubscribe.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-01-03 11:31:32 +0100
committerMax Kellermann <max@duempel.org>2013-01-03 17:49:47 +0100
commitd919f8d50ab32a94b8965330297985cd14c45a42 (patch)
tree238445dc46c7206af0859b3f075f9bd0a4026648 /src/ClientSubscribe.cxx
parentd67aa7c19dfaf5c39b49dc8dfc486b4e99f31db1 (diff)
ClientInternal: use std::set for subscriptions
Diffstat (limited to 'src/ClientSubscribe.cxx')
-rw-r--r--src/ClientSubscribe.cxx36
1 files changed, 10 insertions, 26 deletions
diff --git a/src/ClientSubscribe.cxx b/src/ClientSubscribe.cxx
index 31987c6a..3f471495 100644
--- a/src/ClientSubscribe.cxx
+++ b/src/ClientSubscribe.cxx
@@ -27,17 +27,6 @@ extern "C" {
#include <string.h>
-G_GNUC_PURE
-static GSList *
-client_find_subscription(const Client *client, const char *channel)
-{
- for (GSList *i = client->subscriptions; i != NULL; i = g_slist_next(i))
- if (strcmp((const char *)i->data, channel) == 0)
- return i;
-
- return NULL;
-}
-
enum client_subscribe_result
client_subscribe(Client *client, const char *channel)
{
@@ -47,14 +36,13 @@ client_subscribe(Client *client, const char *channel)
if (!client_message_valid_channel_name(channel))
return CLIENT_SUBSCRIBE_INVALID;
- if (client_find_subscription(client, channel) != NULL)
- return CLIENT_SUBSCRIBE_ALREADY;
-
if (client->num_subscriptions >= CLIENT_MAX_SUBSCRIPTIONS)
return CLIENT_SUBSCRIBE_FULL;
- client->subscriptions = g_slist_prepend(client->subscriptions,
- g_strdup(channel));
+ auto r = client->subscriptions.insert(channel);
+ if (!r.second)
+ return CLIENT_SUBSCRIBE_ALREADY;
+
++client->num_subscriptions;
idle_add(IDLE_SUBSCRIPTION);
@@ -65,19 +53,19 @@ client_subscribe(Client *client, const char *channel)
bool
client_unsubscribe(Client *client, const char *channel)
{
- GSList *i = client_find_subscription(client, channel);
- if (i == NULL)
+ const auto i = client->subscriptions.find(channel);
+ if (i == client->subscriptions.end())
return false;
assert(client->num_subscriptions > 0);
- client->subscriptions = g_slist_remove(client->subscriptions, i->data);
+ client->subscriptions.erase(i);
--client->num_subscriptions;
idle_add(IDLE_SUBSCRIPTION);
assert((client->num_subscriptions == 0) ==
- (client->subscriptions == NULL));
+ client->subscriptions.empty());
return true;
}
@@ -85,11 +73,7 @@ client_unsubscribe(Client *client, const char *channel)
void
client_unsubscribe_all(Client *client)
{
- for (GSList *i = client->subscriptions; i != NULL; i = g_slist_next(i))
- g_free(i->data);
-
- g_slist_free(client->subscriptions);
- client->subscriptions = NULL;
+ client->subscriptions.clear();
client->num_subscriptions = 0;
}
@@ -101,7 +85,7 @@ client_push_message(Client *client, const struct client_message *msg)
assert(client_message_defined(msg));
if (client->num_messages >= CLIENT_MAX_MESSAGES ||
- client_find_subscription(client, msg->channel) == NULL)
+ !client->IsSubscribed(msg->channel))
return false;
if (client->messages == NULL)