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
a7d1daee
Commit
a7d1daee
authored
Jan 04, 2013
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
CommandListBuilder: use std::list instead of GSList
parent
77a99cc6
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
24 deletions
+16
-24
ClientProcess.cxx
src/ClientProcess.cxx
+6
-5
CommandListBuilder.cxx
src/CommandListBuilder.cxx
+2
-7
CommandListBuilder.hxx
src/CommandListBuilder.hxx
+8
-12
No files found.
src/ClientProcess.cxx
View file @
a7d1daee
...
...
@@ -29,13 +29,14 @@
#define CLIENT_LIST_MODE_END "command_list_end"
static
enum
command_return
client_process_command_list
(
Client
*
client
,
bool
list_ok
,
GSList
*
list
)
client_process_command_list
(
Client
*
client
,
bool
list_ok
,
std
::
list
<
std
::
string
>
&&
list
)
{
enum
command_return
ret
=
COMMAND_RETURN_OK
;
unsigned
num
=
0
;
for
(
GSList
*
cur
=
list
;
cur
!=
NULL
;
cur
=
g_slist_next
(
cur
)
)
{
char
*
cmd
=
(
char
*
)
cur
->
data
;
for
(
auto
&&
i
:
list
)
{
char
*
cmd
=
&*
i
.
begin
()
;
g_debug
(
"command_process_list: process command
\"
%s
\"
"
,
cmd
);
...
...
@@ -81,11 +82,11 @@ client_process_line(Client *client, char *line)
g_debug
(
"[%u] process command list"
,
client
->
num
);
auto
cmd_list
=
client
->
cmd_list
.
Commit
();
auto
&&
cmd_list
=
client
->
cmd_list
.
Commit
();
ret
=
client_process_command_list
(
client
,
client
->
cmd_list
.
IsOKMode
(),
cmd_list
);
std
::
move
(
cmd_list
)
);
g_debug
(
"[%u] process command "
"list returned %i"
,
client
->
num
,
ret
);
...
...
src/CommandListBuilder.cxx
View file @
a7d1daee
...
...
@@ -25,12 +25,7 @@
void
CommandListBuilder
::
Reset
()
{
for
(
GSList
*
tmp
=
list
;
tmp
!=
NULL
;
tmp
=
g_slist_next
(
tmp
))
g_free
(
tmp
->
data
);
g_slist_free
(
list
);
list
=
nullptr
;
list
.
clear
();
mode
=
Mode
::
DISABLED
;
}
...
...
@@ -42,6 +37,6 @@ CommandListBuilder::Add(const char *cmd)
if
(
size
>
client_max_command_list_size
)
return
false
;
list
=
g_slist_prepend
(
list
,
g_strdup
(
cmd
)
);
list
.
emplace_back
(
cmd
);
return
true
;
}
src/CommandListBuilder.hxx
View file @
a7d1daee
...
...
@@ -20,7 +20,9 @@
#ifndef MPD_COMMAND_LIST_BUILDER_HXX
#define MPD_COMMAND_LIST_BUILDER_HXX
#include <glib.h>
#include <list>
#include <string>
#include <assert.h>
class
CommandListBuilder
{
...
...
@@ -47,7 +49,7 @@ class CommandListBuilder {
/**
* for when in list mode
*/
GSList
*
list
;
std
::
list
<
std
::
string
>
list
;
/**
* Memory consumed by the list.
...
...
@@ -56,10 +58,7 @@ class CommandListBuilder {
public
:
CommandListBuilder
()
:
mode
(
Mode
::
DISABLED
),
list
(
nullptr
),
size
(
0
)
{}
~
CommandListBuilder
()
{
Reset
();
}
:
mode
(
Mode
::
DISABLED
),
size
(
0
)
{}
/**
* Is a command list currently being built?
...
...
@@ -86,7 +85,7 @@ public:
* Begin building a command list.
*/
void
Begin
(
bool
ok
)
{
assert
(
list
==
nullptr
);
assert
(
list
.
empty
()
);
assert
(
mode
==
Mode
::
DISABLED
);
mode
=
(
Mode
)
ok
;
...
...
@@ -100,13 +99,10 @@ public:
/**
* Finishes the list and returns it.
*/
GSList
*
Commit
()
{
std
::
list
<
std
::
string
>
&&
Commit
()
{
assert
(
IsActive
());
/* for scalability reasons, we have prepended each new
command; now we have to reverse it to restore the
correct order */
return
list
=
g_slist_reverse
(
list
);
return
std
::
move
(
list
);
}
};
...
...
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