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
55737e4f
Commit
55737e4f
authored
Jan 18, 2014
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
db/upnp/Util: trimstring() constructs string from buffer
Reduce overhead by omitting the part of the buffer that consists only of whitespace.
parent
f3b4ddee
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
15 additions
and
17 deletions
+15
-17
Device.cxx
src/db/upnp/Device.cxx
+1
-2
Directory.cxx
src/db/upnp/Directory.cxx
+1
-2
Util.cxx
src/db/upnp/Util.cxx
+10
-11
Util.hxx
src/db/upnp/Util.hxx
+3
-2
No files found.
src/db/upnp/Device.cxx
View file @
55737e4f
...
...
@@ -56,8 +56,7 @@ protected:
}
virtual
void
CharacterData
(
const
XML_Char
*
s
,
int
len
)
{
std
::
string
str
(
s
,
len
);
trimstring
(
str
);
std
::
string
str
=
trimstring
(
s
,
len
);
switch
(
m_path
.
back
()[
0
])
{
case
'c'
:
if
(
!
m_path
.
back
().
compare
(
"controlURL"
))
...
...
src/db/upnp/Directory.cxx
View file @
55737e4f
...
...
@@ -156,8 +156,7 @@ protected:
virtual
void
CharacterData
(
const
XML_Char
*
s
,
int
len
)
{
std
::
string
str
(
s
,
len
);
trimstring
(
str
);
std
::
string
str
=
trimstring
(
s
,
len
);
TagType
type
=
tag_table_lookup
(
upnp_tags
,
m_path
.
back
().
c_str
());
...
...
src/db/upnp/Util.cxx
View file @
55737e4f
...
...
@@ -18,6 +18,7 @@
*/
#include "Util.hxx"
#include "util/CharUtil.hxx"
#include <string>
#include <map>
...
...
@@ -27,19 +28,17 @@
#include <upnp/ixml.h>
/** Get rid of white space at both ends */
void
trimstring
(
std
::
string
&
s
,
const
char
*
ws
)
std
::
string
trimstring
(
const
char
*
p
,
size_t
length
)
{
auto
pos
=
s
.
find_first_not_of
(
ws
);
if
(
pos
==
std
::
string
::
npos
)
{
s
.
clear
();
return
;
}
s
.
replace
(
0
,
pos
,
std
::
string
())
;
while
(
length
>
0
&&
IsWhitespaceOrNull
(
p
[
length
-
1
]))
--
length
;
const
char
*
end
=
p
+
length
;
while
(
p
!=
end
&&
IsWhitespaceOrNull
(
*
p
))
++
p
;
pos
=
s
.
find_last_not_of
(
ws
);
if
(
pos
!=
std
::
string
::
npos
&&
pos
!=
s
.
length
()
-
1
)
s
.
replace
(
pos
+
1
,
std
::
string
::
npos
,
std
::
string
());
return
std
::
string
(
p
,
end
);
}
std
::
string
...
...
src/db/upnp/Util.hxx
View file @
55737e4f
...
...
@@ -28,8 +28,9 @@
std
::
string
caturl
(
const
std
::
string
&
s1
,
const
std
::
string
&
s2
);
void
trimstring
(
std
::
string
&
s
,
const
char
*
ws
=
"
\t\n
"
);
gcc_pure
std
::
string
trimstring
(
const
char
*
p
,
size_t
length
);
std
::
string
path_getfather
(
const
std
::
string
&
s
);
...
...
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