]> git.tdb.fi Git - libs/net.git/commitdiff
Reserve space for strings before appending characters
authorMikko Rasa <tdb@tdb.fi>
Fri, 9 Dec 2022 22:27:01 +0000 (00:27 +0200)
committerMikko Rasa <tdb@tdb.fi>
Fri, 9 Dec 2022 22:27:01 +0000 (00:27 +0200)
source/http/utils.cpp

index 2f13576166ba9b128f0a111a1e507a8cb645fb96..8662c2ec4176c452472d1c6984fd13f489b70d1f 100644 (file)
@@ -31,6 +31,7 @@ namespace Http {
 string urlencode(const string &str, EncodeLevel level)
 {
        string result;
+       result.reserve(str.size());
        for(char c: str)
        {
                if(is_reserved(c, level))
@@ -44,6 +45,7 @@ string urlencode(const string &str, EncodeLevel level)
 string urlencode_plus(const string &str, EncodeLevel level)
 {
        string result;
+       result.reserve(str.size());
        for(char c: str)
        {
                if(c==' ')