[Libreoffice-commits] core.git: vcl/source
Mike Kaganski (via logerrit)
logerrit at kemper.freedesktop.org
Wed Feb 24 12:50:25 UTC 2021
vcl/source/font/font.cxx | 23 ++++++++---------------
1 file changed, 8 insertions(+), 15 deletions(-)
New commits:
commit 16901e4ccad95d55d4ae0fa2d6f6103b4177592e
Author: Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Wed Feb 24 10:19:47 2021 +0100
Commit: Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Wed Feb 24 13:49:39 2021 +0100
Simplify static string generation
Change-Id: I838d3900a6f3ba28fd30cd2e3ec7a7f74a7736b4
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111431
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>
diff --git a/vcl/source/font/font.cxx b/vcl/source/font/font.cxx
index 9c5204d190f5..bdc2c8f0095d 100644
--- a/vcl/source/font/font.cxx
+++ b/vcl/source/font/font.cxx
@@ -32,6 +32,7 @@
#include <sft.hxx>
#include <algorithm>
+#include <numeric>
#include <string_view>
#include <rtl/instance.hxx>
@@ -390,23 +391,15 @@ tools::Long Font::GetOrCalculateAverageFontWidth() const
// as close as possible (discussion see documentation in task),
// so calculate it. For discussion of method used, see task
// buffer measure string creation, will always use the same
- static OUString aMeasureString;
-
- if(!aMeasureString.getLength())
- {
- const std::size_t nSize(127 - 32);
- std::array<sal_Unicode, nSize> aArray;
-
- for(sal_Unicode a(0); a < nSize; a++)
- {
- aArray[a] = a + 32;
- }
-
- aMeasureString = OUString(aArray.data());
- }
+ static const OUStringLiteral aMeasureString = [] { // not constexpr yet because of std::iota
+ sal_Unicode aArray[127 - 32 + 1];
+ std::iota(aArray, aArray + SAL_N_ELEMENTS(aArray) - 1, 32);
+ aArray[SAL_N_ELEMENTS(aArray) - 1] = u'\0';
+ return OUStringLiteral(aArray);
+ }();
const double fAverageFontWidth(
- pTempVirtualDevice->GetTextWidth(aMeasureString, aMeasureString.getLength()) /
+ pTempVirtualDevice->GetTextWidth(aMeasureString) /
static_cast<double>(aMeasureString.getLength()));
const_cast<Font*>(this)->mpImplFont->SetCalculatedAverageFontWidth(basegfx::fround(fAverageFontWidth));
#endif
More information about the Libreoffice-commits
mailing list