diff options
author | Florent Le Coz <louiz@louiz.org> | 2015-09-01 04:53:12 +0200 |
---|---|---|
committer | Florent Le Coz <louiz@louiz.org> | 2015-09-01 04:53:12 +0200 |
commit | d7e1214cbcff2d34f45687eff7c083a89bf04802 (patch) | |
tree | 11873b3ecc948bb8c091be1bedc539330810a489 | |
parent | e8f22efe34415db0e1e5cb94635b089b18efe055 (diff) | |
download | biboumi-d7e1214cbcff2d34f45687eff7c083a89bf04802.tar.gz biboumi-d7e1214cbcff2d34f45687eff7c083a89bf04802.tar.bz2 biboumi-d7e1214cbcff2d34f45687eff7c083a89bf04802.tar.xz biboumi-d7e1214cbcff2d34f45687eff7c083a89bf04802.zip |
XmlNode::to_string uses an ostringstream instead of a string
On my poor benchmark, it was infinitesimally faster.
-rw-r--r-- | louloulibs/xmpp/xmpp_stanza.cpp | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/louloulibs/xmpp/xmpp_stanza.cpp b/louloulibs/xmpp/xmpp_stanza.cpp index c66b4be..aec91a7 100644 --- a/louloulibs/xmpp/xmpp_stanza.cpp +++ b/louloulibs/xmpp/xmpp_stanza.cpp @@ -5,6 +5,7 @@ #include <stdexcept> #include <iostream> +#include <sstream> #include <string.h> @@ -207,21 +208,21 @@ const std::string XmlNode::get_name() const std::string XmlNode::to_string() const { - std::string res("<"); - res += this->name; + std::ostringstream res; + res << "<" << this->name; for (const auto& it: this->attributes) - res += " " + it.first + "='" + sanitize(it.second) + "'"; + res << " " << it.first << "='" << sanitize(it.second) + "'"; if (!this->has_children() && this->inner.empty()) - res += "/>"; + res << "/>"; else { - res += ">" + sanitize(this->inner); + res << ">" + sanitize(this->inner); for (const auto& child: this->children) - res += child->to_string(); - res += "</" + this->get_name() + ">"; + res << child->to_string(); + res << "</" << this->get_name() << ">"; } - res += sanitize(this->tail); - return res; + res << sanitize(this->tail); + return res.str(); } bool XmlNode::has_children() const |