Skip to content
This repository was archived by the owner on Jun 12, 2018. It is now read-only.

Commit d59b7c2

Browse files
committed
Optimized string() functions
1 parent 5416b27 commit d59b7c2

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

client_http.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,11 @@ namespace SimpleWeb {
6262
/// Convenience function to return std::string. The stream buffer is consumed.
6363
std::string string() noexcept {
6464
try {
65-
std::stringstream ss;
66-
ss << rdbuf();
67-
return ss.str();
65+
std::string str;
66+
auto size = streambuf.size();
67+
str.resize(size);
68+
read(&str[0], static_cast<std::streamsize>(size));
69+
return str;
6870
}
6971
catch(...) {
7072
return std::string();

server_http.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,11 @@ namespace SimpleWeb {
163163
/// Convenience function to return std::string. The stream buffer is consumed.
164164
std::string string() noexcept {
165165
try {
166-
std::stringstream ss;
167-
ss << rdbuf();
168-
return ss.str();
166+
std::string str;
167+
auto size = streambuf.size();
168+
str.resize(size);
169+
read(&str[0], static_cast<std::streamsize>(size));
170+
return str;
169171
}
170172
catch(...) {
171173
return std::string();

0 commit comments

Comments
 (0)