Mercurial > hg > orthanc
comparison 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 |
comparison
equal
deleted
inserted
replaced
3323:a15a4b9d8c00 | 3325:2e7c5c15ba25 |
---|---|
396 | 396 |
397 #if ORTHANC_ENABLE_BASE64 == 1 | 397 #if ORTHANC_ENABLE_BASE64 == 1 |
398 void Toolbox::EncodeBase64(std::string& result, | 398 void Toolbox::EncodeBase64(std::string& result, |
399 const std::string& data) | 399 const std::string& data) |
400 { | 400 { |
401 result = base64_encode(data); | 401 base64_encode(result, data); |
402 } | 402 } |
403 | 403 |
404 void Toolbox::DecodeBase64(std::string& result, | 404 void Toolbox::DecodeBase64(std::string& result, |
405 const std::string& data) | 405 const std::string& data) |
406 { | 406 { |
414 // This is not a valid character for a Base64 string | 414 // This is not a valid character for a Base64 string |
415 throw OrthancException(ErrorCode_BadFileFormat); | 415 throw OrthancException(ErrorCode_BadFileFormat); |
416 } | 416 } |
417 } | 417 } |
418 | 418 |
419 result = base64_decode(data); | 419 base64_decode(result, data); |
420 } | 420 } |
421 | 421 |
422 | 422 |
423 bool Toolbox::DecodeDataUriScheme(std::string& mime, | 423 bool Toolbox::DecodeDataUriScheme(std::string& mime, |
424 std::string& content, | 424 std::string& content, |
443 | 443 |
444 void Toolbox::EncodeDataUriScheme(std::string& result, | 444 void Toolbox::EncodeDataUriScheme(std::string& result, |
445 const std::string& mime, | 445 const std::string& mime, |
446 const std::string& content) | 446 const std::string& content) |
447 { | 447 { |
448 result = "data:" + mime + ";base64," + base64_encode(content); | 448 result = "data:" + mime + ";base64,"; |
449 base64_encode(result, content); | |
449 } | 450 } |
450 | 451 |
451 #endif | 452 #endif |
452 | 453 |
453 | 454 |