aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-01-18 13:36:50 +0100
committerMax Kellermann <max@duempel.org>2014-01-18 13:36:50 +0100
commit55737e4ff63df685f1603eadc3105cda38b7da9b (patch)
treeba54beb753aa9cd8c5d40e6f88f5f8e129a6dbac
parentf3b4ddee6c9ede15ed0009651d47d260fcd12fd3 (diff)
downloadmpd-55737e4ff63df685f1603eadc3105cda38b7da9b.tar.gz
mpd-55737e4ff63df685f1603eadc3105cda38b7da9b.tar.xz
mpd-55737e4ff63df685f1603eadc3105cda38b7da9b.zip
db/upnp/Util: trimstring() constructs string from buffer
Reduce overhead by omitting the part of the buffer that consists only of whitespace.
Diffstat (limited to '')
-rw-r--r--src/db/upnp/Device.cxx3
-rw-r--r--src/db/upnp/Directory.cxx3
-rw-r--r--src/db/upnp/Util.cxx21
-rw-r--r--src/db/upnp/Util.hxx5
4 files changed, 15 insertions, 17 deletions
diff --git a/src/db/upnp/Device.cxx b/src/db/upnp/Device.cxx
index 37d68c232..c947f5a14 100644
--- a/src/db/upnp/Device.cxx
+++ b/src/db/upnp/Device.cxx
@@ -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"))
diff --git a/src/db/upnp/Directory.cxx b/src/db/upnp/Directory.cxx
index 3b6428389..757e2e19d 100644
--- a/src/db/upnp/Directory.cxx
+++ b/src/db/upnp/Directory.cxx
@@ -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());
diff --git a/src/db/upnp/Util.cxx b/src/db/upnp/Util.cxx
index afe68e619..fc9ef6281 100644
--- a/src/db/upnp/Util.cxx
+++ b/src/db/upnp/Util.cxx
@@ -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
diff --git a/src/db/upnp/Util.hxx b/src/db/upnp/Util.hxx
index 08fe5f497..ba5633331 100644
--- a/src/db/upnp/Util.hxx
+++ b/src/db/upnp/Util.hxx
@@ -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);