diff Core/Toolbox.cpp @ 3325:2e7c5c15ba25

reserve size for base64 decoding + avoid copy. In a test in WASM, encoding 3MB took 110ms instead of 1400ms previously
author Alain Mazy <alain@mazy.be>
date Thu, 21 Mar 2019 09:57:31 +0100
parents b32b7c44a223
children b21d4cc8e5d1
line wrap: on
line diff
--- a/Core/Toolbox.cpp	Tue Mar 19 09:00:34 2019 +0100
+++ b/Core/Toolbox.cpp	Thu Mar 21 09:57:31 2019 +0100
@@ -398,7 +398,7 @@
   void Toolbox::EncodeBase64(std::string& result, 
                              const std::string& data)
   {
-    result = base64_encode(data);
+    base64_encode(result, data);
   }
 
   void Toolbox::DecodeBase64(std::string& result, 
@@ -416,7 +416,7 @@
       }
     }
 
-    result = base64_decode(data);
+    base64_decode(result, data);
   }
 
 
@@ -445,7 +445,8 @@
                                     const std::string& mime,
                                     const std::string& content)
   {
-    result = "data:" + mime + ";base64," + base64_encode(content);
+    result = "data:" + mime + ";base64,";
+    base64_encode(result, content);
   }
 
 #endif