Skip to content

Commit

Permalink
Fix performance regression when encoding to a string
Browse files Browse the repository at this point in the history
Using a stringstream is still the way to go here.
  • Loading branch information
jimporter committed Aug 9, 2024
1 parent 2904af7 commit ed2b677
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions include/bencode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -824,9 +824,9 @@ namespace bencode {

template<typename T>
std::string encode(T &&t) {
std::string result;
encode(std::back_inserter(result), std::forward<T>(t));
return result;
std::stringstream ss;
encode(std::ostreambuf_iterator(ss), std::forward<T>(t));
return ss.str();
}

template<typename T>
Expand Down

0 comments on commit ed2b677

Please sign in to comment.