summaryrefslogtreecommitdiff
path: root/sal/osl/unx
diff options
context:
space:
mode:
authorNoel Grandin <noelgrandin@gmail.com>2019-10-17 20:33:50 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2019-10-21 08:36:01 +0200
commit0f874472c672175135520101837ff0c9d4701d7f (patch)
treefa6a504bdfc7d5d838caed7cfb87793321797290 /sal/osl/unx
parent9112c18524c9f5e67d6cbb282586a439e3020cdb (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/osl/unx')
-rw-r--r--sal/osl/unx/file_url.cxx9
-rw-r--r--sal/osl/unx/tempfile.cxx12
2 files changed, 12 insertions, 9 deletions
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;