Skip to content

Commit ed2b677

Browse files
committed
Fix performance regression when encoding to a string
Using a stringstream is still the way to go here.
1 parent 2904af7 commit ed2b677

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

include/bencode.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -824,9 +824,9 @@ namespace bencode {
824824

825825
template<typename T>
826826
std::string encode(T &&t) {
827-
std::string result;
828-
encode(std::back_inserter(result), std::forward<T>(t));
829-
return result;
827+
std::stringstream ss;
828+
encode(std::ostreambuf_iterator(ss), std::forward<T>(t));
829+
return ss.str();
830830
}
831831

832832
template<typename T>

0 commit comments

Comments
 (0)