Skip to content

Commit aeaec10

Browse files
ttsugriyanonrig
authored andcommitted
Avoid potentially unnecessary string reallocs.
In case dest is not created using a subset of the `input` `result.reserve(input.size())` would result in increasing `result`'s size with likely reallocation.
1 parent cf504eb commit aeaec10

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/unicode.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,9 +422,10 @@ std::string percent_encode(const std::string_view input,
422422
return std::string(input);
423423
}
424424

425-
std::string result(input.substr(0, std::distance(input.begin(), pointer)));
425+
std::string result;
426426
result.reserve(input.length()); // in the worst case, percent encoding might
427427
// produce 3 characters.
428+
result.append(input.substr(0, std::distance(input.begin(), pointer)));
428429

429430
for (; pointer != input.end(); pointer++) {
430431
if (character_sets::bit_at(character_set, *pointer)) {

0 commit comments

Comments
 (0)