summaryrefslogtreecommitdiff
path: root/stoc
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 /stoc
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 'stoc')
-rw-r--r--stoc/source/inspect/introspection.cxx2
-rw-r--r--stoc/source/uriproc/ExternalUriReferenceTranslator.cxx4
-rw-r--r--stoc/source/uriproc/UriReference.cxx2
-rw-r--r--stoc/source/uriproc/UriReferenceFactory.cxx7
-rw-r--r--stoc/source/uriproc/UriSchemeParser_vndDOTsunDOTstarDOTscript.cxx9
-rw-r--r--stoc/source/uriproc/VndSunStarPkgUrlReferenceFactory.cxx2
-rw-r--r--stoc/test/uriproc/test_uriproc.cxx2
7 files changed, 14 insertions, 14 deletions
diff --git a/stoc/source/inspect/introspection.cxx b/stoc/source/inspect/introspection.cxx
index b5cebfd268d5..58434b2f51ea 100644
--- a/stoc/source/inspect/introspection.cxx
+++ b/stoc/source/inspect/introspection.cxx
@@ -1438,7 +1438,7 @@ struct TypeKey {
// the chance of matches between different implementations' getTypes(),
// but the old scheme of using getImplementationId() would have missed
// those matches, too:
- OUStringBuffer b;
+ OUStringBuffer b(static_cast<int>(theTypes.size() * 64));
for (const css::uno::Type& rType : theTypes) {
b.append(rType.getTypeName());
b.append('*'); // arbitrary delimiter not used by type grammar
diff --git a/stoc/source/uriproc/ExternalUriReferenceTranslator.cxx b/stoc/source/uriproc/ExternalUriReferenceTranslator.cxx
index f7b99bf9a8e7..9e21c5aef79f 100644
--- a/stoc/source/uriproc/ExternalUriReferenceTranslator.cxx
+++ b/stoc/source/uriproc/ExternalUriReferenceTranslator.cxx
@@ -92,7 +92,7 @@ OUString Translator::translateToInternal(
return externalUriReference;
}
sal_Int32 i = RTL_CONSTASCII_LENGTH("file:");
- OUStringBuffer buf;
+ OUStringBuffer buf(128);
buf.append(std::u16string_view(externalUriReference).substr(0, i));
// Some environments (e.g., Java) produce illegal file URLs without an
// authority part; treat them as having an empty authority part:
@@ -140,7 +140,7 @@ OUString Translator::translateToExternal(
return internalUriReference;
}
sal_Int32 i = RTL_CONSTASCII_LENGTH("file://");
- OUStringBuffer buf;
+ OUStringBuffer buf(128);
buf.append(std::u16string_view(internalUriReference).substr(0, i));
rtl_TextEncoding encoding = osl_getThreadTextEncoding();
for (bool path = true;;) {
diff --git a/stoc/source/uriproc/UriReference.cxx b/stoc/source/uriproc/UriReference.cxx
index dd4d68d3144e..75ed1abaa2a4 100644
--- a/stoc/source/uriproc/UriReference.cxx
+++ b/stoc/source/uriproc/UriReference.cxx
@@ -51,7 +51,7 @@ UriReference::~UriReference() {}
OUString UriReference::getUriReference()
{
osl::MutexGuard g(m_mutex);
- OUStringBuffer buf;
+ OUStringBuffer buf(128);
if (!m_scheme.isEmpty()) {
buf.append(m_scheme);
buf.append(':');
diff --git a/stoc/source/uriproc/UriReferenceFactory.cxx b/stoc/source/uriproc/UriReferenceFactory.cxx
index 3a5f30b850de..bb96a55d88ed 100644
--- a/stoc/source/uriproc/UriReferenceFactory.cxx
+++ b/stoc/source/uriproc/UriReferenceFactory.cxx
@@ -356,7 +356,7 @@ css::uno::Reference< css::uri::XUriReference > Factory::parse(
if (n >= 0) {
scheme = uriReference.copy(0, n);
schemeSpecificPart = uriReference.copy(n + 1, fragment - (n + 1));
- OUStringBuffer buf;
+ OUStringBuffer buf(128);
buf.append("com.sun.star.uri.UriSchemeParser_");
for (sal_Int32 i = 0; i < scheme.getLength(); ++i) {
sal_Unicode c = scheme[i];
@@ -488,7 +488,8 @@ css::uno::Reference< css::uri::XUriReference > Factory::makeAbsolute(
}
return parse(abs.makeStringAndClear());
} else {
- OUStringBuffer abs(baseUriReference->getScheme());
+ OUStringBuffer abs(128);
+ abs.append(baseUriReference->getScheme());
abs.append(':');
if (uriReference->hasAuthority()) {
abs.append("//");
@@ -597,7 +598,7 @@ css::uno::Reference< css::uri::XUriReference > Factory::makeRelative(
uriReference->getScheme())) {
return clone(uriReference);
} else {
- OUStringBuffer rel;
+ OUStringBuffer rel(128);
bool omitQuery = false;
if ((baseUriReference->hasAuthority() != uriReference->hasAuthority())
|| !equalIgnoreEscapeCase(
diff --git a/stoc/source/uriproc/UriSchemeParser_vndDOTsunDOTstarDOTscript.cxx b/stoc/source/uriproc/UriSchemeParser_vndDOTsunDOTstarDOTscript.cxx
index 1191a711262f..b63fad9d529e 100644
--- a/stoc/source/uriproc/UriSchemeParser_vndDOTsunDOTstarDOTscript.cxx
+++ b/stoc/source/uriproc/UriSchemeParser_vndDOTsunDOTstarDOTscript.cxx
@@ -282,10 +282,9 @@ void SAL_CALL UrlReference::setName(OUString const & name)
sal_Int32 i = 0;
parsePart(m_base.m_path, true, &i);
- OUStringBuffer newPath;
- newPath.append(encodeNameOrParamFragment(name));
- newPath.append(std::u16string_view(m_base.m_path).substr(i));
- m_base.m_path = newPath.makeStringAndClear();
+ auto tmp = std::u16string_view(m_base.m_path).substr(i);
+ m_base.m_path = encodeNameOrParamFragment(name) +
+ rtl::OUStringView(tmp.data(), tmp.length());
}
sal_Bool UrlReference::hasParameter(OUString const & key)
@@ -314,7 +313,7 @@ void UrlReference::setParameter(OUString const & key, OUString const & value)
i = m_base.m_path.getLength();
}
- OUStringBuffer newPath;
+ OUStringBuffer newPath(128);
newPath.append(std::u16string_view(m_base.m_path).substr(0, i));
if (!bExistent) {
newPath.append( m_base.m_path.indexOf('?') < 0 ? '?' : '&' );
diff --git a/stoc/source/uriproc/VndSunStarPkgUrlReferenceFactory.cxx b/stoc/source/uriproc/VndSunStarPkgUrlReferenceFactory.cxx
index ff8aa8e84a8e..b6e926bd2e7c 100644
--- a/stoc/source/uriproc/VndSunStarPkgUrlReferenceFactory.cxx
+++ b/stoc/source/uriproc/VndSunStarPkgUrlReferenceFactory.cxx
@@ -94,7 +94,7 @@ Factory::createVndSunStarPkgUrlReference(
" XVndSunStarPkgUrlReferenceFactory.createVndSunStarPkgUrlReference");
}
if (authority->isAbsolute() && !authority->hasFragment()) {
- OUStringBuffer buf;
+ OUStringBuffer buf(128);
buf.append("vnd.sun.star.pkg://");
buf.append(
rtl::Uri::encode(
diff --git a/stoc/test/uriproc/test_uriproc.cxx b/stoc/test/uriproc/test_uriproc.cxx
index 3cb36343ce32..14132fa70031 100644
--- a/stoc/test/uriproc/test_uriproc.cxx
+++ b/stoc/test/uriproc/test_uriproc.cxx
@@ -82,7 +82,7 @@ OString createTestAssertEqualMessage(
char const * expectedExpr, char const * actualExpr, T3 const & expected,
T4 const & actual)
{
- OUStringBuffer buf;
+ OUStringBuffer buf(512);
buf.appendAscii(token1);
buf.append('|');
append(buf, token2);