diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2023-03-13 12:11:04 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2023-03-13 13:05:41 +0000 |
commit | 2cb2e2b9c1d55bbbc639997ca30fd6b57a81bfb2 (patch) | |
tree | 63657503f9076375fb29eafb19dcab41b2528509 /include/rtl | |
parent | cd50669485ebea3c45d4c555ad90ff484e22f429 (diff) |
Introduce OUStringBuffer::insert taking OUStringConcat
Avoids some (re)allocations, and aligns with already existing append
Change-Id: I536ba50f56fc560c0f6e8c0a8b65bd4248896a8e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148777
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'include/rtl')
-rw-r--r-- | include/rtl/ustrbuf.hxx | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/include/rtl/ustrbuf.hxx b/include/rtl/ustrbuf.hxx index af7d0d0d9ef6..cdfb28ab556c 100644 --- a/include/rtl/ustrbuf.hxx +++ b/include/rtl/ustrbuf.hxx @@ -43,6 +43,7 @@ #include "sal/types.h" #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING" +#include "o3tl/safeint.hxx" #include "rtl/stringconcat.hxx" #endif @@ -1015,6 +1016,38 @@ public: } #endif +#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING" + /** + @overload + @internal + */ + template <typename T1, typename T2> + OUStringBuffer& insert(sal_Int32 offset, OUStringConcat<T1, T2>&& c) + { + const size_t l = c.length(); + if (l == 0) + return *this; + if (l > o3tl::make_unsigned(std::numeric_limits<sal_Int32>::max() - pData->length)) + throw std::bad_alloc(); + + rtl_uStringbuffer_insert(&pData, &nCapacity, offset, nullptr, l); + + /* insert the new characters */ + c.addData(pData->buffer + offset); + return *this; + } + + /** + @overload + @internal + */ + template <typename T, std::size_t N> + OUStringBuffer& insert(sal_Int32 offset, StringNumberBase<sal_Unicode, T, N>&& c) + { + return insert(offset, c.buf, c.length); + } +#endif + /** Inserts the string representation of the <code>char</code> array argument into this string buffer. |