Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
a2297558
Commit
a2297558
authored
Jan 03, 2013
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MessageCommands: use std::set instead of GHashTable
parent
84cdf0ca
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
26 deletions
+8
-26
MessageCommands.cxx
src/MessageCommands.cxx
+8
-26
No files found.
src/MessageCommands.cxx
View file @
a2297558
...
...
@@ -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
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment