diff options
author | Noel Grandin <noelgrandin@gmail.com> | 2019-10-17 20:33:50 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-10-23 08:55:00 +0200 |
commit | c68be56c295c8dda3043c80d4641575ec2799e55 (patch) | |
tree | 40fc9a82e021498f7cebe76e59bec5bb85d6385c /comphelper | |
parent | 437dc68285dab0f08a1ded2193d86d64f560cd9b (diff) |
size some stringbuffer to prevent re-alloc
Change-Id: I385587a922c555c320a45dcc6d644315b72510e9
Reviewed-on: https://gerrit.libreoffice.org/81278
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'comphelper')
-rw-r--r-- | comphelper/qa/unit/base64_test.cxx | 16 | ||||
-rw-r--r-- | comphelper/source/misc/docpasswordhelper.cxx | 2 |
2 files changed, 11 insertions, 7 deletions
diff --git a/comphelper/qa/unit/base64_test.cxx b/comphelper/qa/unit/base64_test.cxx index 60f6c68d5631..97f7b78aae7a 100644 --- a/comphelper/qa/unit/base64_test.cxx +++ b/comphelper/qa/unit/base64_test.cxx @@ -49,16 +49,18 @@ public: void Base64Test::testBase64Encode() { - OUStringBuffer aBuffer; + OUStringBuffer aBuffer(32); uno::Sequence<sal_Int8> inputSequence; inputSequence = { 0, 0, 0, 0, 0, 1, 2, 3 }; comphelper::Base64::encode(aBuffer, inputSequence); - CPPUNIT_ASSERT_EQUAL(OUString("AAAAAAABAgM="), aBuffer.makeStringAndClear()); + CPPUNIT_ASSERT_EQUAL(OUString("AAAAAAABAgM="), aBuffer.toString()); + aBuffer.setLength(0); inputSequence = { 5, 2, 3, 0, 0, 1, 2, 3 }; comphelper::Base64::encode(aBuffer, inputSequence); - CPPUNIT_ASSERT_EQUAL(OUString("BQIDAAABAgM="), aBuffer.makeStringAndClear()); + CPPUNIT_ASSERT_EQUAL(OUString("BQIDAAABAgM="), aBuffer.toString()); + aBuffer.setLength(0); inputSequence = { sal_Int8(sal_uInt8(200)), 31, 77, 111, 0, 1, 2, 3 }; comphelper::Base64::encode(aBuffer, inputSequence); @@ -84,16 +86,18 @@ void Base64Test::testBase64Decode() void Base64Test::testBase64EncodeForOStringBuffer() { - OStringBuffer aBuffer; + OStringBuffer aBuffer(32); uno::Sequence<sal_Int8> inputSequence; inputSequence = { 0, 0, 0, 0, 0, 1, 2, 3 }; comphelper::Base64::encode(aBuffer, inputSequence); - CPPUNIT_ASSERT_EQUAL(OString("AAAAAAABAgM="), aBuffer.makeStringAndClear()); + CPPUNIT_ASSERT_EQUAL(OString("AAAAAAABAgM="), aBuffer.toString()); + aBuffer.setLength(0); inputSequence = { 5, 2, 3, 0, 0, 1, 2, 3 }; comphelper::Base64::encode(aBuffer, inputSequence); - CPPUNIT_ASSERT_EQUAL(OString("BQIDAAABAgM="), aBuffer.makeStringAndClear()); + CPPUNIT_ASSERT_EQUAL(OString("BQIDAAABAgM="), aBuffer.toString()); + aBuffer.setLength(0); inputSequence = { sal_Int8(sal_uInt8(200)), 31, 77, 111, 0, 1, 2, 3 }; comphelper::Base64::encode(aBuffer, inputSequence); diff --git a/comphelper/source/misc/docpasswordhelper.cxx b/comphelper/source/misc/docpasswordhelper.cxx index cf665dd6c147..989863fefbc6 100644 --- a/comphelper/source/misc/docpasswordhelper.cxx +++ b/comphelper/source/misc/docpasswordhelper.cxx @@ -308,7 +308,7 @@ OUString DocPasswordHelper::GetOoxHashAsBase64( css::uno::Sequence<sal_Int8> aSeq( GetOoxHashAsSequence( rPassword, rSaltValue, nSpinCount, eIterCount, rAlgorithmName)); - OUStringBuffer aBuf; + OUStringBuffer aBuf((aSeq.getLength()+2)/3*4); comphelper::Base64::encode( aBuf, aSeq); return aBuf.makeStringAndClear(); } |