Optimized string() functions

This commit is contained in:
eidheim 2018-06-02 20:21:52 +02:00
commit d59b7c234c
2 changed files with 10 additions and 6 deletions

View file

@ -62,9 +62,11 @@ namespace SimpleWeb {
/// Convenience function to return std::string. The stream buffer is consumed.
std::string string() noexcept {
try {
std::stringstream ss;
ss << rdbuf();
return ss.str();
std::string str;
auto size = streambuf.size();
str.resize(size);
read(&str[0], static_cast<std::streamsize>(size));
return str;
}
catch(...) {
return std::string();

View file

@ -163,9 +163,11 @@ namespace SimpleWeb {
/// Convenience function to return std::string. The stream buffer is consumed.
std::string string() noexcept {
try {
std::stringstream ss;
ss << rdbuf();
return ss.str();
std::string str;
auto size = streambuf.size();
str.resize(size);
read(&str[0], static_cast<std::streamsize>(size));
return str;
}
catch(...) {
return std::string();