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
5462f34e
Commit
5462f34e
authored
Dec 23, 2010
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
string_util: add function strchug_fast()
Replace g_strchug() calls with a cheaper implementation.
parent
0958ed58
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
64 additions
and
10 deletions
+64
-10
conf.c
src/conf.c
+4
-4
extm3u_playlist_plugin.c
src/playlist/extm3u_playlist_plugin.c
+2
-1
playlist_database.c
src/playlist_database.c
+2
-1
song_save.c
src/song_save.c
+2
-1
string_util.c
src/string_util.c
+9
-0
string_util.h
src/string_util.h
+41
-0
tokenizer.c
src/tokenizer.c
+4
-3
No files found.
src/conf.c
View file @
5462f34e
...
...
@@ -270,7 +270,7 @@ config_read_block(FILE *fp, int *count, char *string, GError **error_r)
}
(
*
count
)
++
;
line
=
g_strchug
(
line
);
line
=
strchug_fast
(
line
);
if
(
*
line
==
0
||
*
line
==
CONF_COMMENT
)
continue
;
...
...
@@ -278,7 +278,7 @@ config_read_block(FILE *fp, int *count, char *string, GError **error_r)
/* end of this block; return from the function
(and from this "while" loop) */
line
=
g_strchug
(
line
+
1
);
line
=
strchug_fast
(
line
+
1
);
if
(
*
line
!=
0
&&
*
line
!=
CONF_COMMENT
)
{
config_param_free
(
ret
);
g_set_error
(
error_r
,
config_quark
(),
0
,
...
...
@@ -356,7 +356,7 @@ config_read_file(const char *file, GError **error_r)
count
++
;
line
=
g_strchug
(
string
);
line
=
strchug_fast
(
string
);
if
(
*
line
==
0
||
*
line
==
CONF_COMMENT
)
continue
;
...
...
@@ -402,7 +402,7 @@ config_read_file(const char *file, GError **error_r)
return
false
;
}
line
=
g_strchug
(
line
+
1
);
line
=
strchug_fast
(
line
+
1
);
if
(
*
line
!=
0
&&
*
line
!=
CONF_COMMENT
)
{
g_set_error
(
error_r
,
config_quark
(),
0
,
"line %i: Unknown tokens after '{'"
,
...
...
src/playlist/extm3u_playlist_plugin.c
View file @
5462f34e
...
...
@@ -24,6 +24,7 @@
#include "uri.h"
#include "song.h"
#include "tag.h"
#include "string_util.h"
#include <glib.h>
...
...
@@ -89,7 +90,7 @@ extm3u_parse_tag(const char *line)
/* 0 means unknown duration */
duration
=
0
;
name
=
g_strchug
(
endptr
+
1
);
name
=
strchug_fast_c
(
endptr
+
1
);
if
(
*
name
==
0
&&
duration
==
0
)
/* no information available; don't allocate a tag
object */
...
...
src/playlist_database.c
View file @
5462f34e
...
...
@@ -21,6 +21,7 @@
#include "playlist_database.h"
#include "playlist_vector.h"
#include "text_file.h"
#include "string_util.h"
#include <string.h>
#include <stdlib.h>
...
...
@@ -62,7 +63,7 @@ playlist_metadata_load(FILE *fp, struct playlist_vector *pv, const char *name,
}
*
colon
++
=
0
;
value
=
g_strchug
(
colon
);
value
=
strchug_fast_c
(
colon
);
if
(
strcmp
(
line
,
"mtime"
)
==
0
)
pm
.
mtime
=
strtol
(
value
,
NULL
,
10
);
...
...
src/song_save.c
View file @
5462f34e
...
...
@@ -24,6 +24,7 @@
#include "directory.h"
#include "tag.h"
#include "text_file.h"
#include "string_util.h"
#include <glib.h>
...
...
@@ -96,7 +97,7 @@ song_load(FILE *fp, struct directory *parent, const char *uri,
}
*
colon
++
=
0
;
value
=
g_strchug
(
colon
);
value
=
strchug_fast_c
(
colon
);
if
((
type
=
tag_name_parse
(
line
))
!=
TAG_NUM_OF_ITEM_TYPES
)
{
if
(
!
song
->
tag
)
{
...
...
src/string_util.c
View file @
5462f34e
...
...
@@ -24,6 +24,15 @@
#include <assert.h>
const
char
*
strchug_fast_c
(
const
char
*
p
)
{
while
(
*
p
!=
0
&&
g_ascii_isspace
(
*
p
))
++
p
;
return
p
;
}
bool
string_array_contains
(
const
char
*
const
*
haystack
,
const
char
*
needle
)
{
...
...
src/string_util.h
View file @
5462f34e
...
...
@@ -20,9 +20,50 @@
#ifndef MPD_STRING_UTIL_H
#define MPD_STRING_UTIL_H
#include <glib.h>
#include <stdbool.h>
/**
* Remove the "const" attribute from a string pointer. This is a
* dirty hack, don't use it unless you know what you're doing!
*/
G_GNUC_CONST
static
inline
char
*
deconst_string
(
const
char
*
p
)
{
union
{
const
char
*
in
;
char
*
out
;
}
u
=
{
.
in
=
p
,
};
return
u
.
out
;
}
/**
* Returns a pointer to the first non-whitespace character in the
* string, or to the end of the string.
*
* This is a faster version of g_strchug(), because it does not move
* data.
*/
G_GNUC_PURE
const
char
*
strchug_fast_c
(
const
char
*
p
);
/**
* Same as strchug_fast_c(), but works with a writable pointer.
*/
G_GNUC_PURE
static
inline
char
*
strchug_fast
(
char
*
p
)
{
return
deconst_string
(
strchug_fast_c
(
p
));
}
/**
* Checks whether a string array contains the specified string.
*
* @param haystack a NULL terminated list of strings
...
...
src/tokenizer.c
View file @
5462f34e
...
...
@@ -19,6 +19,7 @@
#include "config.h"
#include "tokenizer.h"
#include "string_util.h"
#include <stdbool.h>
#include <assert.h>
...
...
@@ -72,7 +73,7 @@ tokenizer_next_word(char **input_p, GError **error_r)
/* a whitespace: the word ends here */
*
input
=
0
;
/* skip all following spaces, too */
input
=
g_strchug
(
input
+
1
);
input
=
strchug_fast
(
input
+
1
);
break
;
}
...
...
@@ -126,7 +127,7 @@ tokenizer_next_unquoted(char **input_p, GError **error_r)
/* a whitespace: the word ends here */
*
input
=
0
;
/* skip all following spaces, too */
input
=
g_strchug
(
input
+
1
);
input
=
strchug_fast
(
input
+
1
);
break
;
}
...
...
@@ -205,7 +206,7 @@ tokenizer_next_string(char **input_p, GError **error_r)
/* finish the string and return it */
*
dest
=
0
;
*
input_p
=
g_strchug
(
input
);
*
input_p
=
strchug_fast
(
input
);
return
word
;
}
...
...
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