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-21 08:36:01 +0200 |
commit | 0f874472c672175135520101837ff0c9d4701d7f (patch) | |
tree | fa6a504bdfc7d5d838caed7cfb87793321797290 /sal | |
parent | 9112c18524c9f5e67d6cbb282586a439e3020cdb (diff) |
size some stringbuffer to prevent re-alloc
found by the simple expidient of putting asserts in
the resize routine. Where an explicit const size is used,
I started with 32 and kept doubling until that site
did not need resizing anymore.
Change-Id: I998787edc940d0a3ba23b5ac37131ab9ecd300f4
Reviewed-on: https://gerrit.libreoffice.org/81138
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sal')
-rw-r--r-- | sal/Module_sal.mk | 1 | ||||
-rw-r--r-- | sal/osl/unx/file_url.cxx | 9 | ||||
-rw-r--r-- | sal/osl/unx/tempfile.cxx | 12 | ||||
-rw-r--r-- | sal/rtl/bootstrap.cxx | 6 | ||||
-rw-r--r-- | sal/rtl/uri.cxx | 4 |
5 files changed, 17 insertions, 15 deletions
diff --git a/sal/Module_sal.mk b/sal/Module_sal.mk index 4d7a84ee4e61..b7b3732e3db5 100644 --- a/sal/Module_sal.mk +++ b/sal/Module_sal.mk @@ -28,7 +28,6 @@ $(eval $(call gb_Module_add_check_targets,sal,\ $(if $(filter WNT,$(OS)),CppunitTest_sal_comtools) \ CppunitTest_sal_osl_security \ CppunitTest_sal_osl \ - CppunitTest_sal_rtl \ CppunitTest_sal_types \ )) diff --git a/sal/osl/unx/file_url.cxx b/sal/osl/unx/file_url.cxx index d149d31e1252..33fcd2952802 100644 --- a/sal/osl/unx/file_url.cxx +++ b/sal/osl/unx/file_url.cxx @@ -171,8 +171,8 @@ bool decodeFromUtf8(std::u16string_view text, OString * result) { assert(result != nullptr); auto p = text.data(); auto const end = p + text.size(); - OUStringBuffer ubuf; - OStringBuffer bbuf; + OUStringBuffer ubuf(static_cast<int>(text.size())); + OStringBuffer bbuf(PATH_MAX); while (p < end) { rtl::uri::detail::EscapeType t; sal_uInt32 c = rtl::uri::detail::readUcs4(&p, end, true, RTL_TEXTENCODING_UTF8, &t); @@ -935,15 +935,16 @@ oslFileError osl::detail::convertUrlToPathname(OUString const & url, OString * p oslFileError osl::detail::convertPathnameToUrl(OString const & pathname, OUString * url) { assert(url != nullptr); - OUStringBuffer buf("file:"); + OUStringBuffer buf(10+pathname.getLength()); + buf.append("file:"); if (pathname.startsWith("/")) { buf.append("//"); // so if pathname should ever start with "//" that isn't mistaken for an authority // component } for (sal_Size convert = pathname.getLength();;) { - OUStringBuffer ubuf; auto n = std::max(convert, sal_Size(PATH_MAX)); // approximation of required converted size + OUStringBuffer ubuf(static_cast<int>(n)); auto s = ubuf.appendUninitialized(n); sal_uInt32 info; sal_Size converted; diff --git a/sal/osl/unx/tempfile.cxx b/sal/osl/unx/tempfile.cxx index cc29a6f59625..84f44cbd4b32 100644 --- a/sal/osl/unx/tempfile.cxx +++ b/sal/osl/unx/tempfile.cxx @@ -193,15 +193,17 @@ static oslFileError osl_create_temp_file_impl_( len_base_dir = rtl_uString_getLength(pustr_base_directory); - rtl_uStringbuffer_newFromStr_WithLength( + rtl_uString_new_WithLength( &tmp_file_path, - rtl_uString_getStr(const_cast<rtl_uString*>(pustr_base_directory)), - len_base_dir); + (len_base_dir + 1 + RAND_NAME_LENGTH)); + capacity = len_base_dir + 1 + RAND_NAME_LENGTH; - rtl_uStringbuffer_ensureCapacity( + rtl_uStringbuffer_insert( &tmp_file_path, &capacity, - (len_base_dir + 1 + RAND_NAME_LENGTH)); + 0, + rtl_uString_getStr(const_cast<rtl_uString*>(pustr_base_directory)), + len_base_dir); offset_file_name = len_base_dir; diff --git a/sal/rtl/bootstrap.cxx b/sal/rtl/bootstrap.cxx index 4417246e9eea..7f5d4317636a 100644 --- a/sal/rtl/bootstrap.cxx +++ b/sal/rtl/bootstrap.cxx @@ -800,7 +800,7 @@ void SAL_CALL rtl_bootstrap_expandMacros(rtl_uString ** macro) void rtl_bootstrap_encode(rtl_uString const * value, rtl_uString ** encoded) { OSL_ASSERT(value); - OUStringBuffer b; + OUStringBuffer b(value->length+5); for (sal_Int32 i = 0; i < value->length; ++i) { sal_Unicode c = value->buffer[i]; @@ -868,7 +868,7 @@ OUString expandMacros( ExpandRequestLink const * requestStack) { SAL_INFO("sal.bootstrap", "expandMacros called with: " << text); - OUStringBuffer buf; + OUStringBuffer buf(2048); for (sal_Int32 i = 0; i < text.getLength();) { @@ -975,7 +975,7 @@ OUString expandMacros( } else { - OUStringBuffer kbuf; + OUStringBuffer kbuf(text.getLength()); for (; i < text.getLength();) { sal_Int32 j = i; diff --git a/sal/rtl/uri.cxx b/sal/rtl/uri.cxx index ae88e18b8774..592b92c88525 100644 --- a/sal/rtl/uri.cxx +++ b/sal/rtl/uri.cxx @@ -638,7 +638,7 @@ void SAL_CALL rtl_uriEncode(rtl_uString * pText, sal_Bool const * pCharClass, sal_Unicode const * p = pText->buffer; sal_Unicode const * pEnd = p + pText->length; - sal_Int32 nCapacity = pText->length; + sal_Int32 nCapacity = 256; rtl_uString_new_WithLength(pResult, nCapacity); while (p < pEnd) @@ -758,9 +758,9 @@ sal_Bool SAL_CALL rtl_uriConvertRelToAbs(rtl_uString * pBaseUriRef, { // Use the strict parser algorithm from RFC 3986, section 5.2, to turn the // relative URI into an absolute one: - OUStringBuffer aBuffer; Components aRelComponents; parseUriRef(pRelUriRef, &aRelComponents); + OUStringBuffer aBuffer(256); if (aRelComponents.aScheme.isPresent()) { |