db/upnp/Util: trimstring() constructs string from buffer
Reduce overhead by omitting the part of the buffer that consists only of whitespace.
This commit is contained in:
parent
f3b4ddee6c
commit
55737e4ff6
|
@ -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"))
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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;
|
||||
|
||||
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());
|
||||
const char *end = p + length;
|
||||
while (p != end && IsWhitespaceOrNull(*p))
|
||||
++p;
|
||||
|
||||
return std::string(p, end);
|
||||
}
|
||||
|
||||
std::string
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue