[Libreoffice-commits] core.git: include/o3tl

2023-10-27 Thread Stephan Bergmann (via logerrit)
 include/o3tl/intcmp.hxx |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

New commits:
commit 550eb0d45117836cdea2112ee37a3fd7219a90b5
Author: Stephan Bergmann 
AuthorDate: Fri Oct 27 09:38:20 2023 +0200
Commit: Stephan Bergmann 
CommitDate: Fri Oct 27 11:11:00 2023 +0200

Clarify that o3tl::cmp_* is still needed for LLVM 12 libc++ for now

...which is apparently used by Android builds, so
 "Directly use std::cmp_*, 
drop
o3tl::cmp_*" cannot go in, yet

Change-Id: If8b3ef1e647b6e33c43d0fe5737daf63eda0b761
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/158524
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/o3tl/intcmp.hxx b/include/o3tl/intcmp.hxx
index 1324afcdaf7d..dbc10d9052b0 100644
--- a/include/o3tl/intcmp.hxx
+++ b/include/o3tl/intcmp.hxx
@@ -20,7 +20,7 @@ namespace o3tl
 {
 // An approximation of the C++20 integer comparison functions
 // ( 
"Safe integral
-// comparisons"):
+// comparisons"), still missing from LLVM 12 libc++:
 #if defined __cpp_lib_integer_comparison_functions
 
 using std::cmp_equal;


[Libreoffice-commits] core.git: include/o3tl sw/inc

2023-10-25 Thread Stephan Bergmann (via logerrit)
 include/o3tl/concepts.hxx |   45 +
 sw/inc/nodeoffset.hxx |9 +++--
 2 files changed, 48 insertions(+), 6 deletions(-)

New commits:
commit dcaa2c4870e0b2662c597f53c46b1df347183e7c
Author: Stephan Bergmann 
AuthorDate: Tue Oct 24 22:07:26 2023 +0200
Commit: Stephan Bergmann 
CommitDate: Wed Oct 25 10:27:26 2023 +0200

Use std::signed_integral concept

...which, unlike std::is_signed, also requires that T is an integer type, 
not
just any arithmetic type, but which appears to fit well here anyway.

But LLVM 12 libc++, which is apparently used by Android builds, only 
provides a
bare-bones  that lacks std::signed_integral (among others), so 
for now
introduce o3tl/concepts.hxx providing what's missing (incl. std::integral 
and
std::unsigned_integral, for some kind of consistency).

Change-Id: I1c37d37fa1b57b5e3bf24c9e44f3973003905cb2
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/158406
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/o3tl/concepts.hxx b/include/o3tl/concepts.hxx
new file mode 100644
index ..261d063ebca2
--- /dev/null
+++ b/include/o3tl/concepts.hxx
@@ -0,0 +1,45 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; 
fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#pragma once
+
+#include 
+
+#include 
+
+// LLVM 12 libc++ only provides a bare-bones  that lacks most of its 
C++20 content, so
+// replicate here fore now what we need:
+
+#if defined __cpp_lib_concepts
+
+namespace o3tl
+{
+using std::integral;
+using std::signed_integral;
+using std::unsigned_integral;
+}
+
+#else
+
+#include 
+
+namespace o3tl
+{
+// Taken from the C++20 spec:
+
+template  concept integral = std::is_integral_v;
+
+template  concept signed_integral = integral&& 
std::is_signed_v;
+
+template  concept unsigned_integral = integral && 
!signed_integral;
+}
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/sw/inc/nodeoffset.hxx b/sw/inc/nodeoffset.hxx
index 035925855b31..f6deac6609b0 100644
--- a/sw/inc/nodeoffset.hxx
+++ b/sw/inc/nodeoffset.hxx
@@ -10,23 +10,20 @@
 
 #include 
 #include "swdllapi.h"
+#include 
 #include 
 #include 
 
 typedef o3tl::strong_int SwNodeOffset;
 
 /* Just to make it easier to write arithmetic with these types */
-template 
-inline typename std::enable_if::value, SwNodeOffset>::type
-operator+(SwNodeOffset a, T n)
+template  inline SwNodeOffset operator+(SwNodeOffset 
a, T n)
 {
 return a + SwNodeOffset(n);
 }
 
 /* Just to make it easier to write arithmetic with these types */
-template 
-inline typename std::enable_if::value, SwNodeOffset>::type
-operator-(SwNodeOffset a, T n)
+template  inline SwNodeOffset operator-(SwNodeOffset 
a, T n)
 {
 return a - SwNodeOffset(n);
 }


[Libreoffice-commits] core.git: include/o3tl

2023-10-12 Thread Stephan Bergmann (via logerrit)
 include/o3tl/string_view.hxx |6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

New commits:
commit 92f3d912f703e3c84cbd9e0b43a34d12d130e3dd
Author: Stephan Bergmann 
AuthorDate: Wed Oct 11 15:33:49 2023 +0200
Commit: Stephan Bergmann 
CommitDate: Thu Oct 12 09:34:07 2023 +0200

Fix typos in C++ feature test macros

...that were accidentally made in e6fe048ded34a322007547d4d31e32c598aa4993 
"Some
more string_view use, add o3tl::starts/ends_with"

Change-Id: I06470f705d1f51f98daffabe544c0194dfc34ee3
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157832
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/o3tl/string_view.hxx b/include/o3tl/string_view.hxx
index 07278be8e529..1e5db5eb0227 100644
--- a/include/o3tl/string_view.hxx
+++ b/include/o3tl/string_view.hxx
@@ -265,7 +265,7 @@ template >
 constexpr bool ends_with(std::basic_string_view sv,
  std::basic_string_view x) noexcept
 {
-#if defined __cpp_lib_ends_ends_with
+#if defined __cpp_lib_starts_ends_with
 return sv.ends_with(x);
 #else
 return sv.size() >= x.size()
@@ -275,7 +275,7 @@ constexpr bool ends_with(std::basic_string_view sv,
 template >
 constexpr bool ends_with(std::basic_string_view sv, charT x) 
noexcept
 {
-#if defined __cpp_lib_ends_ends_with
+#if defined __cpp_lib_starts_ends_with
 return sv.ends_with(x);
 #else
 return !sv.empty() && traits::eq(sv.back(), x);
@@ -284,7 +284,7 @@ constexpr bool ends_with(std::basic_string_view sv, charT x) noex
 template >
 constexpr bool ends_with(std::basic_string_view sv, charT 
const* x)
 {
-#if defined __cpp_lib_ends_ends_with
+#if defined __cpp_lib_starts_ends_with
 return sv.ends_with(x);
 #else
 return ends_with(sv, std::basic_string_view(x));


[Libreoffice-commits] core.git: include/o3tl

2023-05-05 Thread Stephan Bergmann (via logerrit)
 include/o3tl/string_view.hxx |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

New commits:
commit f614e082055dd3cad9885d6e1968d71f1e1b5a05
Author: Stephan Bergmann 
AuthorDate: Fri May 5 08:08:02 2023 +0200
Commit: Stephan Bergmann 
CommitDate: Fri May 5 10:36:38 2023 +0200

Fix typo in assert

I accidentally broke this in fa0c012d6c06e9a92093dacf997fe3151272648e 
"Provide
std::u16string_view based o3tl::iterateCodePoints" when moving the body of 
code
from rtl_uString_iterateCodePoints to here and then adapting it from 
sal_Int32-
base OUString to std::size_t-based std::u16string_view.

Change-Id: I5bd97413ac8c8482f409ad5be3797fef47191d33
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151409
Tested-by: Stephan Bergmann 
Reviewed-by: Stephan Bergmann 

diff --git a/include/o3tl/string_view.hxx b/include/o3tl/string_view.hxx
index 2609a32efe35..b5b64d5991dd 100644
--- a/include/o3tl/string_view.hxx
+++ b/include/o3tl/string_view.hxx
@@ -527,7 +527,7 @@ inline sal_uInt32 iterateCodePoints(std::u16string_view 
string, std::size_t* ind
 }
 while (incrementCodePoints < 0)
 {
-assert(n >= 0);
+assert(n > 0);
 cu = string[--n];
 if (rtl::isLowSurrogate(cu) && n != 0 && rtl::isHighSurrogate(string[n 
- 1]))
 {


[Libreoffice-commits] core.git: include/o3tl

2023-05-05 Thread Andrea Gelmini (via logerrit)
 include/o3tl/string_view.hxx |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

New commits:
commit 140d09520cc92135093d61e8b6b0de9cc26a4edc
Author: Andrea Gelmini 
AuthorDate: Thu May 4 23:14:39 2023 +0200
Commit: Julien Nabet 
CommitDate: Fri May 5 09:12:51 2023 +0200

Fix typo

Change-Id: If680acecd66a59f2fcd12aa8121bdf548404ca51
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151405
Tested-by: Jenkins
Reviewed-by: Julien Nabet 

diff --git a/include/o3tl/string_view.hxx b/include/o3tl/string_view.hxx
index 6ed7af121cc9..2609a32efe35 100644
--- a/include/o3tl/string_view.hxx
+++ b/include/o3tl/string_view.hxx
@@ -508,7 +508,7 @@ inline double toDouble(std::string_view str)
 return rtl_math_stringToDouble(str.data(), str.data() + str.size(), '.', 
0, nullptr, nullptr);
 }
 
-// Similar to OUString::iterateCodePoins, but for std::string_view.
+// Similar to OUString::iterateCodePoints, but for std::string_view.
 // If preAdjustIndex is true: prior to any other operation, *indexUtf16 is 
adjusted by -1 if it
 // originally pointed into the middle of a surrogate pair.
 inline sal_uInt32 iterateCodePoints(std::u16string_view string, std::size_t* 
indexUtf16,


[Libreoffice-commits] core.git: include/o3tl sal/rtl

2023-05-04 Thread Stephan Bergmann (via logerrit)
 include/o3tl/string_view.hxx |   54 +++
 sal/rtl/ustring.cxx  |   49 ++-
 2 files changed, 67 insertions(+), 36 deletions(-)

New commits:
commit fa0c012d6c06e9a92093dacf997fe3151272648e
Author: Stephan Bergmann 
AuthorDate: Thu May 4 14:09:53 2023 +0200
Commit: Stephan Bergmann 
CommitDate: Thu May 4 17:51:23 2023 +0200

Provide std::u16string_view based o3tl::iterateCodePoints

...as requested in the comments of
 "a11y: Fix returning 
unpaired
surrogates when retrieving characters" (incl. the additional preAdjustIndex
parameter).

The type of the indexUtf16 parameter obviously needed to be adapted to
std::u16string_view's std::size_t.  But there is no obvious best choice for 
the
type of the incrementCodePoints parameter (int? std::ssize_t?), so lets 
leave it
as sal_Int32.

For simplicity of avoiding a Library_o3tl, and to allow 
o3tl::iterateCodePoints
to be used in the implementation of rtl_uString_iterateCodePoints now,
o3tl::iterateCodePoints is provided as an inline function defined in the 
include
file.

Change-Id: I8280ca11d2a943bd2b7150a266807b358f321a72
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151366
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/o3tl/string_view.hxx b/include/o3tl/string_view.hxx
index 6084b5692cb5..6ed7af121cc9 100644
--- a/include/o3tl/string_view.hxx
+++ b/include/o3tl/string_view.hxx
@@ -17,8 +17,10 @@
 #include 
 
 #include 
+#include 
 #include 
 #include 
+#include 
 
 namespace o3tl
 {
@@ -506,6 +508,58 @@ inline double toDouble(std::string_view str)
 return rtl_math_stringToDouble(str.data(), str.data() + str.size(), '.', 
0, nullptr, nullptr);
 }
 
+// Similar to OUString::iterateCodePoins, but for std::string_view.
+// If preAdjustIndex is true: prior to any other operation, *indexUtf16 is 
adjusted by -1 if it
+// originally pointed into the middle of a surrogate pair.
+inline sal_uInt32 iterateCodePoints(std::u16string_view string, std::size_t* 
indexUtf16,
+sal_Int32 incrementCodePoints = 1, bool 
preAdjustIndex = false)
+{
+std::size_t n;
+char16_t cu;
+sal_uInt32 cp;
+assert(indexUtf16 != nullptr);
+n = *indexUtf16;
+assert(n <= string.length());
+if (preAdjustIndex && n != 0 && rtl::isHighSurrogate(string[n - 1])
+&& rtl::isLowSurrogate(string[n]))
+{
+--n;
+}
+while (incrementCodePoints < 0)
+{
+assert(n >= 0);
+cu = string[--n];
+if (rtl::isLowSurrogate(cu) && n != 0 && rtl::isHighSurrogate(string[n 
- 1]))
+{
+--n;
+}
+++incrementCodePoints;
+}
+assert(n < string.length());
+cu = string[n];
+if (rtl::isHighSurrogate(cu) && string.length() - n >= 2 && 
rtl::isLowSurrogate(string[n + 1]))
+{
+cp = rtl::combineSurrogates(cu, string[n + 1]);
+}
+else
+{
+cp = cu;
+}
+while (incrementCodePoints > 0)
+{
+assert(n < string.length());
+cu = string[n++];
+if (rtl::isHighSurrogate(cu) && n != string.length() && 
rtl::isLowSurrogate(string[n]))
+{
+++n;
+}
+--incrementCodePoints;
+}
+assert(n <= string.length());
+*indexUtf16 = n;
+return cp;
+}
+
 } // namespace
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/sal/rtl/ustring.cxx b/sal/rtl/ustring.cxx
index 45ab6e166871..fc23cf37a338 100644
--- a/sal/rtl/ustring.cxx
+++ b/sal/rtl/ustring.cxx
@@ -26,6 +26,9 @@
 #include 
 
 #include 
+#include 
+#include 
+#include 
 #include 
 #include 
 #include 
@@ -769,43 +772,17 @@ sal_uInt32 SAL_CALL rtl_uString_iterateCodePoints(
 rtl_uString const * string, sal_Int32 * indexUtf16,
 sal_Int32 incrementCodePoints)
 {
-sal_Int32 n;
-sal_Unicode cu;
-sal_uInt32 cp;
 assert(string != nullptr && indexUtf16 != nullptr);
-n = *indexUtf16;
-assert(n >= 0 && n <= string->length);
-while (incrementCodePoints < 0) {
-assert(n > 0);
-cu = string->buffer[--n];
-if (rtl::isLowSurrogate(cu) && n != 0 &&
-rtl::isHighSurrogate(string->buffer[n - 1]))
-{
---n;
-}
-++incrementCodePoints;
-}
-assert(n >= 0 && n < string->length);
-cu = string->buffer[n];
-if (rtl::isHighSurrogate(cu) && string->length - n >= 2 &&
-rtl::isLowSurrogate(string->buffer[n + 1]))
-{
-cp = rtl::combineSurrogates(cu, string->buffer[n + 1]);
-} else {
-cp = cu;
-}
-while (incrementCodePoints > 0) {
-assert(n < string->length);
-cu = string->buffer[n++];
-if (rtl::isHighSurrogate(cu) && n != string->length &&
-

[Libreoffice-commits] core.git: include/o3tl lingucomponent/source

2023-04-22 Thread Mike Kaganski (via logerrit)
 include/o3tl/char16_t2wchar_t.hxx   |4 
 lingucomponent/source/numbertext/numbertext.cxx |2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

New commits:
commit 0f6ec3939df6b0e3263fc07a2067bbbfc6421ac7
Author: Mike Kaganski 
AuthorDate: Sat Apr 22 10:28:20 2023 +0200
Commit: Mike Kaganski 
CommitDate: Sat Apr 22 12:46:01 2023 +0200

Introduce o3tl::toU converting wstring_view to u16string_view

Change-Id: I5be9aa767020c2516984e47fcd0f51d4661fdf17
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150779
Tested-by: Jenkins
Reviewed-by: Mike Kaganski 

diff --git a/include/o3tl/char16_t2wchar_t.hxx 
b/include/o3tl/char16_t2wchar_t.hxx
index cf0415343147..fcbbaf079ce3 100644
--- a/include/o3tl/char16_t2wchar_t.hxx
+++ b/include/o3tl/char16_t2wchar_t.hxx
@@ -11,6 +11,8 @@
 
 #include 
 
+#include 
+
 namespace o3tl
 {
 #if defined _WIN32
@@ -37,6 +39,8 @@ inline wchar_t* toW(char16_t* p) { return 
reinterpret_cast(p); }
 inline wchar_t const* toW(char16_t const* p) { return reinterpret_cast(p); }
 inline char16_t* toU(wchar_t* p) { return reinterpret_cast(p); }
 inline char16_t const* toU(wchar_t const* p) { return 
reinterpret_cast(p); }
+
+inline std::u16string_view toU(std::wstring_view v) { return { toU(v.data()), 
v.size() }; }
 #endif
 }
 
diff --git a/lingucomponent/source/numbertext/numbertext.cxx 
b/lingucomponent/source/numbertext/numbertext.cxx
index 4f868adb74d8..aec03e1f5e8e 100644
--- a/lingucomponent/source/numbertext/numbertext.cxx
+++ b/lingucomponent/source/numbertext/numbertext.cxx
@@ -128,7 +128,7 @@ OUString SAL_CALL NumberText_Impl::getNumberText(const 
OUString& rText, const Lo
 bool result = m_aNumberText.numbertext(sResult, aLangCode.getStr());
 DBG_ASSERT(result, "numbertext: false");
 #if defined(_WIN32)
-OUString aResult(o3tl::toU(sResult.c_str()));
+OUString aResult(o3tl::toU(sResult));
 #else
 OUString aResult = OUString::fromUtf8(Numbertext::wstring2string(sResult));
 #endif


[Libreoffice-commits] core.git: include/o3tl solenv/clang-format

2023-04-22 Thread Mike Kaganski (via logerrit)
 include/o3tl/char16_t2wchar_t.hxx |   32 
 solenv/clang-format/excludelist   |1 -
 2 files changed, 8 insertions(+), 25 deletions(-)

New commits:
commit ab55c7bffddc1a4c8f3d971d24bae297a15f3346
Author: Mike Kaganski 
AuthorDate: Sat Apr 22 10:25:57 2023 +0200
Commit: Mike Kaganski 
CommitDate: Sat Apr 22 12:45:38 2023 +0200

clang-format char16_t2wchar_t.hxx

Change-Id: I5b86fb372702e3a6fdb3e4aa6846c4bc2e754307
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150778
Tested-by: Jenkins
Reviewed-by: Mike Kaganski 

diff --git a/include/o3tl/char16_t2wchar_t.hxx 
b/include/o3tl/char16_t2wchar_t.hxx
index 6ffab02e78c9..cf0415343147 100644
--- a/include/o3tl/char16_t2wchar_t.hxx
+++ b/include/o3tl/char16_t2wchar_t.hxx
@@ -7,18 +7,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  */
 
-#ifndef INCLUDED_O3TL_CHAR16_T2WCHAR_T_HXX
-#define INCLUDED_O3TL_CHAR16_T2WCHAR_T_HXX
+#pragma once
 
 #include 
 
-namespace o3tl {
-
+namespace o3tl
+{
 #if defined _WIN32
 // Helpers for safe conversion between wchar_t and char16_t in MSVC
 
 static_assert(sizeof(char16_t) == sizeof(wchar_t),
-"These helper functions are only applicable to implementations with 16-bit 
wchar_t");
+  "These helper functions are only applicable to implementations 
with 16-bit wchar_t");
 
 // While other implementations define wchar_t as 32-bit integral value, and 
mostly use
 // char-based UTF-8 string APIs, in MSVC wchar_t is (non-conformant) 16-bit, 
and Unicode
@@ -34,26 +33,11 @@ static_assert(sizeof(char16_t) == sizeof(wchar_t),
 //
 // Use these helpers for wchar_t (WSTR, WCHAR, OLESTR etc) to char16_t 
(sal_Unicode) string
 // conversions instead of reinterpret-cast in Windows-specific code.
-inline wchar_t * toW(char16_t * p)
-{
-return reinterpret_cast(p);
-}
-inline wchar_t const * toW(char16_t const * p)
-{
-return reinterpret_cast(p);
-}
-inline char16_t * toU(wchar_t * p)
-{
-return reinterpret_cast(p);
-}
-inline char16_t const * toU(wchar_t const * p)
-{
-return reinterpret_cast(p);
-}
+inline wchar_t* toW(char16_t* p) { return reinterpret_cast(p); }
+inline wchar_t const* toW(char16_t const* p) { return reinterpret_cast(p); }
+inline char16_t* toU(wchar_t* p) { return reinterpret_cast(p); }
+inline char16_t const* toU(wchar_t const* p) { return 
reinterpret_cast(p); }
 #endif
-
 }
 
-#endif
-
 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/solenv/clang-format/excludelist b/solenv/clang-format/excludelist
index 211e9ca30c04..35d750b22cc9 100644
--- a/solenv/clang-format/excludelist
+++ b/solenv/clang-format/excludelist
@@ -5296,7 +5296,6 @@ include/linguistic/lngprophelp.hxx
 include/linguistic/misc.hxx
 include/linguistic/spelldta.hxx
 include/o3tl/any.hxx
-include/o3tl/char16_t2wchar_t.hxx
 include/o3tl/cow_wrapper.hxx
 include/o3tl/enumarray.hxx
 include/o3tl/enumrange.hxx


[Libreoffice-commits] core.git: include/o3tl

2023-04-14 Thread Mike Kaganski (via logerrit)
 include/o3tl/string_view.hxx |   16 
 1 file changed, 8 insertions(+), 8 deletions(-)

New commits:
commit 43b893f3a1812b1ca4380267e78ff1b846c41436
Author: Mike Kaganski 
AuthorDate: Fri Apr 14 11:34:13 2023 +0200
Commit: Mike Kaganski 
CommitDate: Fri Apr 14 13:33:46 2023 +0200

Another micro-optimization

I was surprised to see that all three major compilers generate
better code using the pointer arithmetics compared to indices.

Change-Id: I934a840a43159babf51f337b4af7f972424ff4fb
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150323
Tested-by: Jenkins
Reviewed-by: Mike Kaganski 

diff --git a/include/o3tl/string_view.hxx b/include/o3tl/string_view.hxx
index 36b786e534e2..6084b5692cb5 100644
--- a/include/o3tl/string_view.hxx
+++ b/include/o3tl/string_view.hxx
@@ -433,20 +433,20 @@ inline bool implIsWhitespace(sal_Unicode c)
 template >
 std::basic_string_view trim(std::basic_string_view str)
 {
-size_t nFirst = 0;
-size_t nLast = str.size();
+auto pFirst = str.data();
+auto pLast = pFirst + str.size();
 
-while ((nFirst < nLast) && internal::implIsWhitespace(str.data()[nFirst]))
-++nFirst;
+while ((pFirst < pLast) && internal::implIsWhitespace(*pFirst))
+++pFirst;
 
-if (nFirst == nLast)
+if (pFirst == pLast)
 return {};
 
 do
---nLast;
-while (internal::implIsWhitespace(str.data()[nLast]));
+--pLast;
+while (internal::implIsWhitespace(*pLast));
 
-return { str.data() + nFirst, nLast - nFirst + 1 };
+return std::basic_string_view(pFirst, pLast - pFirst + 1);
 }
 
 // "deduction guides"


[Libreoffice-commits] core.git: include/o3tl

2023-04-13 Thread Mike Kaganski (via logerrit)
 include/o3tl/string_view.hxx |   25 ++---
 1 file changed, 6 insertions(+), 19 deletions(-)

New commits:
commit 9470fca71139f9e439ce61b4c93dd33022c2cc6d
Author: Mike Kaganski 
AuthorDate: Thu Apr 13 08:51:34 2023 +0200
Commit: Mike Kaganski 
CommitDate: Thu Apr 13 13:21:37 2023 +0200

deduplicate o3tl::trim

Change-Id: I5d4b3555b59b5abf622c389662e83cbd0f7d142d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150213
Tested-by: Jenkins
Reviewed-by: Mike Kaganski 

diff --git a/include/o3tl/string_view.hxx b/include/o3tl/string_view.hxx
index c3a7649a..91088aaae745 100644
--- a/include/o3tl/string_view.hxx
+++ b/include/o3tl/string_view.hxx
@@ -380,8 +380,9 @@ inline bool implIsWhitespace(sal_Unicode c)
 }
 } // namespace internal
 
-// Like OUString::trim, but for std::u16string_view:
-inline std::u16string_view trim(std::u16string_view str)
+// Like OUString::trim, but for std::[u16]string_view:
+template >
+std::basic_string_view trim(std::basic_string_view str)
 {
 size_t nFirst = 0;
 size_t nLast = str.size();
@@ -399,24 +400,10 @@ inline std::u16string_view trim(std::u16string_view str)
 return { str.data() + nFirst, nLast - nFirst + 1 };
 }
 
-// Like OString::trim, but for std::string_view:
-inline std::string_view trim(std::string_view str)
-{
-size_t nFirst = 0;
-size_t nLast = str.size();
-
-while ((nFirst < nLast) && internal::implIsWhitespace(str.data()[nFirst]))
-++nFirst;
-
-if (nFirst == nLast)
-return {};
-
-do
---nLast;
-while (internal::implIsWhitespace(str.data()[nLast]));
+// "deduction guides"
 
-return { str.data() + nFirst, nLast - nFirst + 1 };
-}
+inline auto trim(std::string_view str) { return trim<>(str); }
+inline auto trim(std::u16string_view str) { return trim<>(str); }
 
 // Like OString::toInt32, but for std::string_view:
 inline sal_Int32 toInt32(std::u16string_view str, sal_Int16 radix = 10)


[Libreoffice-commits] core.git: include/o3tl sal/rtl

2023-04-12 Thread Mike Kaganski (via logerrit)
 include/o3tl/string_view.hxx |   58 +++
 sal/rtl/strtmpl.hxx  |   91 ++-
 2 files changed, 48 insertions(+), 101 deletions(-)

New commits:
commit d4257802159e672035fab164b0cabd9222f18515
Author: Mike Kaganski 
AuthorDate: Wed Apr 12 16:48:30 2023 +0200
Commit: Mike Kaganski 
CommitDate: Wed Apr 12 19:48:43 2023 +0200

Use o3tl::trim in strtmpl.hxx

Change-Id: I4de8658c36c21fe07fa45f697cf3145c567a95c0
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150210
Tested-by: Jenkins
Reviewed-by: Mike Kaganski 

diff --git a/include/o3tl/string_view.hxx b/include/o3tl/string_view.hxx
index 2ccc4f828a03..c3a7649a 100644
--- a/include/o3tl/string_view.hxx
+++ b/include/o3tl/string_view.hxx
@@ -362,7 +362,6 @@ constexpr bool ends_with(std::u16string_view sv, 
std::u16string_view x,
 
 namespace internal
 {
-// copy of implIsWhitespace from sal/rtl/strtmpl.hxx
 inline bool implIsWhitespace(sal_Unicode c)
 {
 /* Space or Control character? */
@@ -370,12 +369,11 @@ inline bool implIsWhitespace(sal_Unicode c)
 return true;
 
 /* Only in the General Punctuation area Space or Control characters are 
included? */
-if ((c < 0x2000) || (c > 0x206F))
+if ((c < 0x2000) || (c > 0x2029))
 return false;
 
-if (((c >= 0x2000) && (c <= 0x200B)) || /* All Spaces   */
-(c == 0x2028) || /* LINE SEPARATOR   */
-(c == 0x2029)) /* PARAGRAPH SEPARATOR  */
+if ((c <= 0x200B) || /* U+2000 - U+200B All Spaces */
+(c >= 0x2028)) /* U+2028 LINE SEPARATOR, U+2029 PARAGRAPH SEPARATOR */
 return true;
 
 return false;
@@ -383,47 +381,41 @@ inline bool implIsWhitespace(sal_Unicode c)
 } // namespace internal
 
 // Like OUString::trim, but for std::u16string_view:
-// copy of the trimView code from sal/rtl/strtmpl.hxx
 inline std::u16string_view trim(std::u16string_view str)
 {
-sal_Int32 nLen = str.size();
-sal_Int32 nPreSpaces = 0;
-sal_Int32 nPostSpaces = 0;
-sal_Int32 nIndex = str.size() - 1;
+size_t nFirst = 0;
+size_t nLast = str.size();
 
-while ((nPreSpaces < nLen) && internal::implIsWhitespace(*(str.data() + 
nPreSpaces)))
-nPreSpaces++;
+while ((nFirst < nLast) && internal::implIsWhitespace(str.data()[nFirst]))
+++nFirst;
 
-while ((nIndex > nPreSpaces) && internal::implIsWhitespace(*(str.data() + 
nIndex)))
-{
-nPostSpaces++;
-nIndex--;
-}
+if (nFirst == nLast)
+return {};
+
+do
+--nLast;
+while (internal::implIsWhitespace(str.data()[nLast]));
 
-return std::u16string_view{ str.data() + nPreSpaces,
-static_cast(nLen - nPostSpaces - 
nPreSpaces) };
+return { str.data() + nFirst, nLast - nFirst + 1 };
 }
 
 // Like OString::trim, but for std::string_view:
-// copy of the trimView code from sal/rtl/strtmpl.hxx
 inline std::string_view trim(std::string_view str)
 {
-sal_Int32 nLen = str.size();
-sal_Int32 nPreSpaces = 0;
-sal_Int32 nPostSpaces = 0;
-sal_Int32 nIndex = str.size() - 1;
+size_t nFirst = 0;
+size_t nLast = str.size();
 
-while ((nPreSpaces < nLen) && internal::implIsWhitespace(*(str.data() + 
nPreSpaces)))
-nPreSpaces++;
+while ((nFirst < nLast) && internal::implIsWhitespace(str.data()[nFirst]))
+++nFirst;
 
-while ((nIndex > nPreSpaces) && internal::implIsWhitespace(*(str.data() + 
nIndex)))
-{
-nPostSpaces++;
-nIndex--;
-}
+if (nFirst == nLast)
+return {};
+
+do
+--nLast;
+while (internal::implIsWhitespace(str.data()[nLast]));
 
-return std::string_view{ str.data() + nPreSpaces,
- static_cast(nLen - nPostSpaces - 
nPreSpaces) };
+return { str.data() + nFirst, nLast - nFirst + 1 };
 }
 
 // Like OString::toInt32, but for std::string_view:
diff --git a/sal/rtl/strtmpl.hxx b/sal/rtl/strtmpl.hxx
index 7ec3af82cf94..cbf34fba2ed7 100644
--- a/sal/rtl/strtmpl.hxx
+++ b/sal/rtl/strtmpl.hxx
@@ -35,6 +35,7 @@
 #include "strimp.hxx"
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -153,24 +154,6 @@ inline sal_Int16 implGetDigit(sal_Unicode ch, sal_Int16 
nRadix)
 return (n < nRadix) ? n : -1;
 }
 
-inline bool implIsWhitespace(sal_Unicode c)
-{
-/* Space or Control character? */
-if ((c <= 32) && c)
-return true;
-
-/* Only in the General Punctuation area Space or Control characters are 
included? */
-if ((c < 0x2000) || (c > 0x206F))
-return false;
-
-if (((c >= 0x2000) && (c <= 0x200B)) ||/* All Spaces   */
-(c == 0x2028) ||   /* LINE SEPARATOR   */
-(c == 0x2029)) /* PARAGRAPH SEPARATOR  */
-return true;
-
-return false;
-}
-
 /* === */
 /* C-String 

[Libreoffice-commits] core.git: include/o3tl vcl/source

2022-11-07 Thread Stephan Bergmann (via logerrit)
 include/o3tl/restoreguard.hxx |   40 
 vcl/source/fontsubset/cff.cxx |7 +++
 2 files changed, 43 insertions(+), 4 deletions(-)

New commits:
commit 2469c623d7985e9e5db54ed8f96df02219def74d
Author: Stephan Bergmann 
AuthorDate: Mon Nov 7 10:58:08 2022 +0100
Commit: Stephan Bergmann 
CommitDate: Tue Nov 8 07:14:21 2022 +0100

Introduce o3tl::RestoreGuard

Change-Id: Ic0c1a73668e990c91ef6e90e8c01e669761fe356
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142403
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/o3tl/restoreguard.hxx b/include/o3tl/restoreguard.hxx
new file mode 100644
index ..19075be3dcea
--- /dev/null
+++ b/include/o3tl/restoreguard.hxx
@@ -0,0 +1,40 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; 
fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#pragma once
+
+#include 
+
+// A convenience guard class that captures a given object's value on guard 
construction and restores
+// it on guard destruction:
+namespace o3tl
+{
+template  class RestoreGuard
+{
+public:
+RestoreGuard(T& object)
+: object_(object)
+, value_(object)
+{
+}
+
+~RestoreGuard() { object_ = value_; }
+
+private:
+RestoreGuard(RestoreGuard&) = delete;
+RestoreGuard(RestoreGuard&&) = delete;
+void operator=(RestoreGuard&) = delete;
+void operator=(RestoreGuard&&) = delete;
+
+T& object_;
+T value_;
+};
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/vcl/source/fontsubset/cff.cxx b/vcl/source/fontsubset/cff.cxx
index 6d1cac5040b5..c398ccb18b98 100644
--- a/vcl/source/fontsubset/cff.cxx
+++ b/vcl/source/fontsubset/cff.cxx
@@ -24,6 +24,7 @@
 
 #include 
 
+#include 
 #include 
 #include 
 #include 
@@ -1541,8 +1542,8 @@ const char* CffSubsetterContext::getString( int nStringID)
 return pStringIds[ nStringID];
 
 // else get the string from the StringIndex table
-const U8* pReadPtr = mpReadPtr;
-const U8* pReadEnd = mpReadEnd;
+o3tl::RestoreGuard pReadPtr(mpReadPtr);
+o3tl::RestoreGuard pReadEnd(mpReadEnd);
 nStringID -= nStdStrings;
 int nLen = seekIndexData( mnStringIdxBase, nStringID);
 // assert( nLen >= 0);
@@ -1559,8 +1560,6 @@ const char* CffSubsetterContext::getString( int nStringID)
 aNameBuf[i] = *(mpReadPtr++);
 aNameBuf[ nLen] = '\0';
 }
-mpReadPtr = pReadPtr;
-mpReadEnd = pReadEnd;
 return aNameBuf;
 }
 


[Libreoffice-commits] core.git: include/o3tl

2022-11-05 Thread Stephan Bergmann (via logerrit)
 include/o3tl/sprintf.hxx |   41 +
 1 file changed, 41 insertions(+)

New commits:
commit 327d1b012f1c3d33fc4160576d25bb57488fca7b
Author: Stephan Bergmann 
AuthorDate: Sat Nov 5 11:30:36 2022 +0100
Commit: Stephan Bergmann 
CommitDate: Sat Nov 5 15:06:42 2022 +0100

Introduce o3tl::sprintf

...in preparation for follow-up commits that will replace many uses of
std::sprintf (which started to emit deprecation warnings with macOS 13 SDK 
now)
across the code base with various alternatives

Change-Id: I9602f1cb0e28d1b70c2356edb52d78dd165f1118
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142317
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/o3tl/sprintf.hxx b/include/o3tl/sprintf.hxx
new file mode 100644
index ..6491f4ad14d6
--- /dev/null
+++ b/include/o3tl/sprintf.hxx
@@ -0,0 +1,41 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; 
fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#pragma once
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+namespace o3tl
+{
+// A drop-in replacement for safe uses of std::sprintf where it is statically 
known that the
+// provided buffer is large enough.  Compared to a plain use of std::sprintf, 
using o3tl::sprintf
+// for one makes it explicit that the call is considerd safe and for another 
avoids deprecation
+// warnings on platforms like the macOS 13 SDK that mark std::sprintf as 
deprecated.  Many simple
+// uses of std::sprintf across the code base can be replaced with alternative 
code using e.g.
+// OString::number.  This is for the remaining formatting-rich cases for which 
there is no easy
+// replacement yet in our C++17 baseline.  Ultimately, it should be removed 
again once alternatives
+// for those remaining cases, like C++20 std::format, are available.
+template 
+int sprintf(char ()[N], char const* format, T&&... arguments)
+{
+auto const n = std::snprintf(s, N, format, std::forward(arguments)...);
+assert(n < 0 || o3tl::make_unsigned(n) < N);
+(void)n;
+return n;
+}
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */


[Libreoffice-commits] core.git: include/o3tl o3tl/qa

2022-10-24 Thread Mike Kaganski (via logerrit)
 include/o3tl/safeint.hxx |4 ++--
 include/o3tl/unit_conversion.hxx |   17 +
 o3tl/qa/test-unit_conversion.cxx |2 ++
 3 files changed, 17 insertions(+), 6 deletions(-)

New commits:
commit 635a0b426e0ab47ec136af7d110354db862c59fa
Author: Mike Kaganski 
AuthorDate: Mon Oct 24 09:37:37 2022 +0200
Commit: Mike Kaganski 
CommitDate: Mon Oct 24 14:07:31 2022 +0200

Fix MulDivSaturate to avoid overflow

Thanks to Caolan
https://gerrit.libreoffice.org/c/core/+/110839/comments/5c47cab2_b0523546

> oss-fuzz has come up with a case of n 9223372036854775807 m 72 d 127
>
> include/o3tl/unit_conversion.hxx:105:28: runtime error: signed integer
> overflow: 9223372036854775807 + 63 cannot be represented in type 'long'

Change-Id: I0fe26f6c854a90cf577a60528d15f3da5471b914
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141711
Tested-by: Jenkins
Reviewed-by: Mike Kaganski 

diff --git a/include/o3tl/safeint.hxx b/include/o3tl/safeint.hxx
index c697a93164aa..a32c6beea142 100644
--- a/include/o3tl/safeint.hxx
+++ b/include/o3tl/safeint.hxx
@@ -27,7 +27,7 @@
 namespace o3tl
 {
 
-template  inline T saturating_add(T a, T b)
+template  inline constexpr T saturating_add(T a, T b)
 {
 if (b >= 0) {
 if (a <= std::numeric_limits::max() - b) {
@@ -44,7 +44,7 @@ template  inline T saturating_add(T a, T b)
 }
 }
 
-template  inline T saturating_sub(T a, T b)
+template  inline constexpr T saturating_sub(T a, T b)
 {
 if (b >= 0) {
 if (a >= std::numeric_limits::min() + b) {
diff --git a/include/o3tl/unit_conversion.hxx b/include/o3tl/unit_conversion.hxx
index 67830f0d16d7..7f0053627f50 100644
--- a/include/o3tl/unit_conversion.hxx
+++ b/include/o3tl/unit_conversion.hxx
@@ -98,11 +98,20 @@ constexpr sal_Int64 MulDiv(I n, sal_Int64 m, sal_Int64 d, 
bool& bOverflow, sal_I
 template , int> = 0>
 constexpr sal_Int64 MulDivSaturate(I n, sal_Int64 m, sal_Int64 d)
 {
-if (!isBetween(n, (SAL_MIN_INT64 + d / 2) / m, (SAL_MAX_INT64 - d / 2) / 
m))
+if (sal_Int64 d_2 = d / 2; !isBetween(n, (SAL_MIN_INT64 + d_2) / m, 
(SAL_MAX_INT64 - d_2) / m))
 {
-if (m > d && !isBetween(n, SAL_MIN_INT64 / m * d + d / 2, 
SAL_MAX_INT64 / m * d - d / 2))
-return n > 0 ? SAL_MAX_INT64 : SAL_MIN_INT64; // saturate
-return (n >= 0 ? n + d / 2 : n - d / 2) / d * m; // divide before 
multiplication
+if (n >= 0)
+{
+if (m > d && std::make_unsigned_t(n) > sal_uInt64(SAL_MAX_INT64 
/ m * d - d_2))
+return SAL_MAX_INT64; // saturate
+return saturating_add(n, d_2) / d * m; // divide 
before multiplication
+}
+else if constexpr (std::is_signed_v) // n < 0; don't compile for 
unsigned n
+{
+if (m > d && n < SAL_MIN_INT64 / m * d + d_2)
+return SAL_MIN_INT64; // saturate
+return saturating_sub(n, d_2) / d * m; // divide before 
multiplication
+}
 }
 return MulDiv(n, m, d);
 }
diff --git a/o3tl/qa/test-unit_conversion.cxx b/o3tl/qa/test-unit_conversion.cxx
index 8b2c05c54549..d140f1da7ec6 100644
--- a/o3tl/qa/test-unit_conversion.cxx
+++ b/o3tl/qa/test-unit_conversion.cxx
@@ -878,4 +878,6 @@ static_assert(o3tl::toTwips(20, o3tl::Length::mm) == 1134);
 // 847 100thmm used to represent 24pt
 static_assert(o3tl::convert(24, o3tl::Length::pt, o3tl::Length::mm100) == 847);
 
+static_assert(o3tl::convertSaturate(SAL_MAX_INT64, 72, 127) == 
5228998320106644552); // no overflow
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */


[Libreoffice-commits] core.git: include/o3tl

2022-07-27 Thread Tomaž Vajngerl (via logerrit)
 include/o3tl/enumarray.hxx |5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

New commits:
commit b9d360405a26ec976e443d501757ad806ffdcd6b
Author: Tomaž Vajngerl 
AuthorDate: Mon Jul 25 15:32:52 2022 +0200
Commit: Tomaž Vajngerl 
CommitDate: Wed Jul 27 09:34:07 2022 +0200

o3tl: use std::array as the container for enumarray

Change-Id: I482140a14a4f18014d89ed5b8ce7c3ca9447b8d6
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137465
Reviewed-by: Noel Grandin 
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl 

diff --git a/include/o3tl/enumarray.hxx b/include/o3tl/enumarray.hxx
index 558ab158bffe..4fd5cab3155f 100644
--- a/include/o3tl/enumarray.hxx
+++ b/include/o3tl/enumarray.hxx
@@ -23,6 +23,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 namespace o3tl {
@@ -92,10 +93,10 @@ public:
 const_iterator   begin() const { return const_iterator(*this, 0); }
 const_iterator   end() const   { return const_iterator(*this, size()); }
 
-V*   data()   { return detail_values; }
+V*   data()   { return detail_values.data(); }
 
 private:
-V detail_values[max_index + 1];
+std::array detail_values;
 };
 
 


[Libreoffice-commits] core.git: include/o3tl

2022-06-20 Thread Stephan Bergmann (via logerrit)
 include/o3tl/enumarray.hxx |1 +
 1 file changed, 1 insertion(+)

New commits:
commit 8dfd706b1fd009eda88a27991fb17affed9659f3
Author: Stephan Bergmann 
AuthorDate: Mon Jun 20 09:42:39 2022 +0200
Commit: Stephan Bergmann 
CommitDate: Mon Jun 20 10:33:20 2022 +0200

Suppress unhelpful cid#1506515

Change-Id: I8d1025a680ea5e4a6ec872478db118837dd91af4
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136137
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/o3tl/enumarray.hxx b/include/o3tl/enumarray.hxx
index 6abfc9ac53ba..558ab158bffe 100644
--- a/include/o3tl/enumarray.hxx
+++ b/include/o3tl/enumarray.hxx
@@ -68,6 +68,7 @@ public:
 static_assert(sizeof... (T) == max_index);
 }
 
+// coverity[uninit_ctor] - by design:
 enumarray() {}
 
 const V& operator[](E index) const


[Libreoffice-commits] core.git: include/o3tl

2022-06-05 Thread Caolán McNamara (via logerrit)
 include/o3tl/safeint.hxx |1 +
 1 file changed, 1 insertion(+)

New commits:
commit 2884ea0ccac3812fcded31327ad4fc9b978fd754
Author: Caolán McNamara 
AuthorDate: Sun Jun 5 14:58:10 2022 +0100
Commit: Caolán McNamara 
CommitDate: Sun Jun 5 18:32:39 2022 +0200

cid#1504664 silence Operands don't affect result

Change-Id: I9ec3ae0e8cb87ab8a98746b8e49fd3f969ea0bd9
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135437
Tested-by: Jenkins
Reviewed-by: Caolán McNamara 

diff --git a/include/o3tl/safeint.hxx b/include/o3tl/safeint.hxx
index 027d283342b5..c697a93164aa 100644
--- a/include/o3tl/safeint.hxx
+++ b/include/o3tl/safeint.hxx
@@ -211,6 +211,7 @@ make_unsigned(T value)
 template constexpr 
std::enable_if_t, T1>
 clamp_to_unsigned(T2 value) {
 if constexpr (std::is_unsigned_v) {
+// coverity[result_independent_of_operands] - suppress warning for 
template
 return value <= std::numeric_limits::max() ? value : 
std::numeric_limits::max();
 } else {
 static_assert(std::is_signed_v);


[Libreoffice-commits] core.git: include/o3tl

2022-06-02 Thread Stephan Bergmann (via logerrit)
 include/o3tl/intcmp.hxx |1 +
 1 file changed, 1 insertion(+)

New commits:
commit 51572f6024da72fbed4d9d1936041962afb1cac7
Author: Stephan Bergmann 
AuthorDate: Thu Jun 2 08:24:21 2022 +0200
Commit: Stephan Bergmann 
CommitDate: Thu Jun 2 09:36:09 2022 +0200

Suppress false positive cid#1504594

Change-Id: I9a4a20a2725a050b7e3d0aa38cb4568e7462926c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135287
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/o3tl/intcmp.hxx b/include/o3tl/intcmp.hxx
index fda9d68f5ff0..1324afcdaf7d 100644
--- a/include/o3tl/intcmp.hxx
+++ b/include/o3tl/intcmp.hxx
@@ -34,6 +34,7 @@ using std::cmp_greater_equal;
 
 template  constexpr bool cmp_equal(T1 value1, T2 
value2) noexcept
 {
+// coverity[same_on_both_sides: FALSE]
 if constexpr (std::is_signed_v == std::is_signed_v)
 {
 return value1 == value2;


[Libreoffice-commits] core.git: include/o3tl

2022-06-01 Thread Stephan Bergmann (via logerrit)
 include/o3tl/intcmp.hxx |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

New commits:
commit c58a51e5f1972eb2f3220d3158801b0c7601f407
Author: Stephan Bergmann 
AuthorDate: Wed Jun 1 12:33:17 2022 +0200
Commit: Stephan Bergmann 
CommitDate: Wed Jun 1 14:48:39 2022 +0200

Fix comment

For one, the functions are already available in C++20.  For another, our
fallback implementation is only an approximation, as it doesn't enforce the
requirement that the involved template types "are standard integer types or
extended integer types" (but which is at least checked in --with-latest-c++
builds against standard libraries that already provide those C++20 
functions).

Change-Id: I91208c185f2db681cf25899d3cd9a9e2912d32a0
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135232
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/o3tl/intcmp.hxx b/include/o3tl/intcmp.hxx
index 2af537b1dead..fda9d68f5ff0 100644
--- a/include/o3tl/intcmp.hxx
+++ b/include/o3tl/intcmp.hxx
@@ -18,7 +18,7 @@
 
 namespace o3tl
 {
-// An implementation of the C++23 integer comparison functions
+// An approximation of the C++20 integer comparison functions
 // ( 
"Safe integral
 // comparisons"):
 #if defined __cpp_lib_integer_comparison_functions


[Libreoffice-commits] core.git: include/o3tl

2022-05-19 Thread Noel Grandin (via logerrit)
 include/o3tl/lazy_update.hxx |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

New commits:
commit c0a035d20f2f2f52c3d6f6b216ea3cd068ea2baa
Author: Noel Grandin 
AuthorDate: Thu May 19 09:36:10 2022 +0200
Commit: Noel Grandin 
CommitDate: Thu May 19 15:37:11 2022 +0200

fix location of #include

after
commit 343eed477ee7b55aa450bbc2aee6786dc0d9a071
clang-tidy modernize-pass-by-value in o3tl

Change-Id: I1800c0ba63abb0862b8c9aef185ebdf416245f3e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134602
Tested-by: Jenkins
Reviewed-by: Noel Grandin 

diff --git a/include/o3tl/lazy_update.hxx b/include/o3tl/lazy_update.hxx
index a3053080c476..6f9325dfd17e 100644
--- a/include/o3tl/lazy_update.hxx
+++ b/include/o3tl/lazy_update.hxx
@@ -1,5 +1,3 @@
-#include 
-
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /*
  * This file is part of the LibreOffice project.
@@ -22,6 +20,8 @@
 #ifndef INCLUDED_O3TL_LAZY_UPDATE_HXX
 #define INCLUDED_O3TL_LAZY_UPDATE_HXX
 
+#include 
+
 namespace o3tl
 {
 /** Update output object lazily


[Libreoffice-commits] core.git: include/o3tl

2022-05-18 Thread Noel Grandin (via logerrit)
 include/o3tl/lazy_update.hxx |4 +++-
 include/o3tl/vector_pool.hxx |5 +++--
 2 files changed, 6 insertions(+), 3 deletions(-)

New commits:
commit 343eed477ee7b55aa450bbc2aee6786dc0d9a071
Author: Noel Grandin 
AuthorDate: Wed May 18 11:55:25 2022 +0200
Commit: Noel Grandin 
CommitDate: Wed May 18 14:08:45 2022 +0200

clang-tidy modernize-pass-by-value in o3tl

Change-Id: I420e023aa6bad3c960a9ec4c52f09b51cdd5ff6d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134520
Tested-by: Jenkins
Reviewed-by: Noel Grandin 

diff --git a/include/o3tl/lazy_update.hxx b/include/o3tl/lazy_update.hxx
index ddff217a722c..a3053080c476 100644
--- a/include/o3tl/lazy_update.hxx
+++ b/include/o3tl/lazy_update.hxx
@@ -1,3 +1,5 @@
+#include 
+
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /*
  * This file is part of the LibreOffice project.
@@ -46,7 +48,7 @@ output( myValue.getOutValue() );
  */
 template class LazyUpdate {
 public:
-LazyUpdate(Func const & func): func_(func), input_(), dirty_(true) {}
+LazyUpdate(Func func): func_(std::move(func)), input_(), dirty_(true) 
{}
 
 In const & getInValue() const { return input_; }
 
diff --git a/include/o3tl/vector_pool.hxx b/include/o3tl/vector_pool.hxx
index 1b94f316f248..eec1a1a3c5af 100644
--- a/include/o3tl/vector_pool.hxx
+++ b/include/o3tl/vector_pool.hxx
@@ -20,6 +20,7 @@
 #ifndef INCLUDED_O3TL_VECTOR_POOL_HXX
 #define INCLUDED_O3TL_VECTOR_POOL_HXX
 
+#include 
 #include 
 
 namespace o3tl
@@ -84,8 +85,8 @@ namespace o3tl
 value(),
 nextFree(-1)
 {}
-explicit type( const ValueType& val ) :
-value(val),
+explicit type( ValueType val ) :
+value(std::move(val)),
 nextFree(-1)
 {}
 


[Libreoffice-commits] core.git: include/o3tl o3tl/qa vcl/source

2022-05-02 Thread Luboš Luňák (via logerrit)
 include/o3tl/lru_map.hxx  |7 ---
 o3tl/qa/test-lru_map.cxx  |   20 
 vcl/source/font/fontcache.cxx |2 +-
 3 files changed, 5 insertions(+), 24 deletions(-)

New commits:
commit 0cc8da4c091ac5784c0b4c2c7850ca8dabffea04
Author: Luboš Luňák 
AuthorDate: Mon May 2 10:52:50 2022 +0200
Commit: Luboš Luňák 
CommitDate: Tue May 3 06:54:54 2022 +0200

remove the o3tl::lru_map "unlimited" hack

It didn't quite make sense before that maxsize == 0 meant no cleanup,
and now with items optionally being count as having size more than 1
it makes even less sense to limit the size to max_size() of the
containers. This comes from 16a338e173083954a9932a3a4005f17230,
so instead make that special caller pass a large size, which in
practice is the same.

Change-Id: Id875862126200ba889211f6e4079ae5921f27650
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133690
Tested-by: Jenkins
Reviewed-by: Luboš Luňák 

diff --git a/include/o3tl/lru_map.hxx b/include/o3tl/lru_map.hxx
index 42cb932786b0..859617e5d988 100644
--- a/include/o3tl/lru_map.hxx
+++ b/include/o3tl/lru_map.hxx
@@ -166,10 +166,10 @@ public:
 typedef list_iterator_t iterator;
 typedef list_const_iterator_t const_iterator;
 
-// a size of 0 effectively disables the LRU cleanup code
 lru_map(size_t nMaxSize)
-: mMaxSize(nMaxSize ? nMaxSize : std::min(mLruMap.max_size(), 
mLruList.max_size()))
+: mMaxSize(nMaxSize)
 {
+assert(mMaxSize > 0);
 }
 ~lru_map()
 {
@@ -182,7 +182,8 @@ public:
 
 void setMaxSize(size_t nMaxSize)
 {
-mMaxSize = nMaxSize ? nMaxSize : std::min(mLruMap.max_size(), 
mLruList.max_size());
+mMaxSize = nMaxSize;
+assert(mMaxSize > 0);
 checkLRUMaxSize();
 }
 
diff --git a/o3tl/qa/test-lru_map.cxx b/o3tl/qa/test-lru_map.cxx
index edc9d7e1bf98..c99a803b3163 100644
--- a/o3tl/qa/test-lru_map.cxx
+++ b/o3tl/qa/test-lru_map.cxx
@@ -27,7 +27,6 @@ public:
 void testLruRemoval();
 void testCustomHash();
 void testRemoveIf();
-void testNoAutoCleanup();
 void testChangeMaxSize();
 void testCustomItemSize();
 
@@ -38,7 +37,6 @@ public:
 CPPUNIT_TEST(testLruRemoval);
 CPPUNIT_TEST(testCustomHash);
 CPPUNIT_TEST(testRemoveIf);
-CPPUNIT_TEST(testNoAutoCleanup);
 CPPUNIT_TEST(testChangeMaxSize);
 CPPUNIT_TEST(testCustomItemSize);
 CPPUNIT_TEST_SUITE_END();
@@ -295,24 +293,6 @@ void lru_map_test::testRemoveIf()
 CPPUNIT_ASSERT_EQUAL(size_t(0), lru.size());
 }
 
-void lru_map_test::testNoAutoCleanup()
-{
-o3tl::lru_map lru(0);
-CPPUNIT_ASSERT_EQUAL(size_t(0), lru.size());
-lru.insert({ 0, 0 });
-lru.insert({ 1, 1 });
-CPPUNIT_ASSERT_EQUAL(size_t(2), lru.size());
-lru.insert({ 0, 0 });
-CPPUNIT_ASSERT_EQUAL(size_t(2), lru.size());
-
-int i = 0;
-for (auto& rPair : lru)
-{
-CPPUNIT_ASSERT_EQUAL(i, rPair.first);
-++i;
-}
-}
-
 void lru_map_test::testChangeMaxSize()
 {
 o3tl::lru_map lru(3);
diff --git a/vcl/source/font/fontcache.cxx b/vcl/source/font/fontcache.cxx
index b98d1bb644cc..9a87d02bcda2 100644
--- a/vcl/source/font/fontcache.cxx
+++ b/vcl/source/font/fontcache.cxx
@@ -88,7 +88,7 @@ bool ImplFontCache::IFSD_Equal::operator()(const 
vcl::font::FontSelectPattern& r
 
 ImplFontCache::ImplFontCache()
 : mpLastHitCacheEntry( nullptr )
-, maFontInstanceList(0)
+, maFontInstanceList(std::numeric_limits::max()) // "unlimited", 
i.e. no cleanup
 // The cache limit is set by the rough number of characters needed to read 
your average Asian newspaper.
 , m_aBoundRectCache(3000)
 {}


[Libreoffice-commits] core.git: include/o3tl

2022-05-02 Thread Andrea Gelmini (via logerrit)
 include/o3tl/lru_map.hxx |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

New commits:
commit 1139013b129fb7f3c58583cdef86b3cdae469f20
Author: Andrea Gelmini 
AuthorDate: Mon May 2 13:23:10 2022 +0200
Commit: Julien Nabet 
CommitDate: Mon May 2 18:52:36 2022 +0200

Fix typo

Change-Id: I63a6ac96679cabe12263a97c3dfdbbd035983b79
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133697
Tested-by: Julien Nabet 
Reviewed-by: Julien Nabet 

diff --git a/include/o3tl/lru_map.hxx b/include/o3tl/lru_map.hxx
index b3c90621edf2..42cb932786b0 100644
--- a/include/o3tl/lru_map.hxx
+++ b/include/o3tl/lru_map.hxx
@@ -55,7 +55,7 @@ template <> class lru_map_base
  *
  * It is optionally possible to specify a function for ValueSize template
  * argument (that can be called as 'size_t func(Value)') that will return
- * a size (cost) for an item istead of the default size of 1 for each item.
+ * a size (cost) for an item instead of the default size of 1 for each item.
  * The size of an item must not change for an item (if needed, re-insert
  * the item). A newly inserted item is guaranteed to be in the container,
  * even if its size exceeds the maximum size.


[Libreoffice-commits] core.git: include/o3tl o3tl/qa

2022-05-02 Thread Luboš Luňák (via logerrit)
 include/o3tl/lru_map.hxx |  136 ++-
 o3tl/qa/test-lru_map.cxx |   30 ++
 2 files changed, 154 insertions(+), 12 deletions(-)

New commits:
commit 46097559ed1ca17c08fd77943e088451d633adfe
Author: Luboš Luňák 
AuthorDate: Sun May 1 18:52:19 2022 +0200
Commit: Tomaž Vajngerl 
CommitDate: Mon May 2 09:26:31 2022 +0200

support custom item size (cost) for o3tl::lru_map

When used with items that may vary significantly in size (such
as SalLayoutGlyphsCache storing glyphs for texts of different sizes)
limiting lru_map to just the number of items performs poorly,
since it may use only small amount of memory if items are small
or it may spent a huge amount of memory if items are large.

As extra optional template argument to o3tl::lru_map that is a functor
that provides cost of item each, and the total size is based on this
instead of each item having cost 1.

Change-Id: I2b326754fe63eb4bd20010d4cea615187407e26c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133672
Tested-by: Jenkins
Reviewed-by: Noel Grandin 
Reviewed-by: Tomaž Vajngerl 

diff --git a/include/o3tl/lru_map.hxx b/include/o3tl/lru_map.hxx
index 41c215255c7a..b3c90621edf2 100644
--- a/include/o3tl/lru_map.hxx
+++ b/include/o3tl/lru_map.hxx
@@ -16,9 +16,31 @@
 #include 
 #include 
 #include 
+#include 
 
 namespace o3tl
 {
+namespace detail
+{
+// Helper base class to keep total cost for lru_map with custom item size.
+// Custom size is specified by the ValueSize functor, the default of each
+// item counting as 1 is specified using the void type.
+template  class lru_map_base
+{
+public:
+// Returns total of ValueSize for all items.
+size_t total_size() const { return mCurrentSize; }
+
+protected:
+size_t mCurrentSize = 0; // sum of ValueSize for all items
+};
+
+// By default cost of each item is 1, so it doesn't need to be tracked.
+template <> class lru_map_base
+{
+};
+} // namespace
+
 /** LRU map
  *
  * Similar to unordered_map (it actually uses it) with additionally 
functionality
@@ -31,10 +53,17 @@ namespace o3tl
  * The implementation is as simple as possible but it still uses O(1) 
complexity
  * for most of the operations with a combination unordered map and linked list.
  *
+ * It is optionally possible to specify a function for ValueSize template
+ * argument (that can be called as 'size_t func(Value)') that will return
+ * a size (cost) for an item istead of the default size of 1 for each item.
+ * The size of an item must not change for an item (if needed, re-insert
+ * the item). A newly inserted item is guaranteed to be in the container,
+ * even if its size exceeds the maximum size.
+ *
  **/
 template ,
-  class KeyEqual = std::equal_to>
-class lru_map final
+  class KeyEqual = std::equal_to, class ValueSize = void>
+class lru_map final : public detail::lru_map_base
 {
 public:
 typedef typename std::pair key_value_pair_t;
@@ -52,14 +81,84 @@ private:
 map_t mLruMap;
 size_t mMaxSize;
 
-void checkLRU()
+void addSize(const Value& value)
+{
+// by default total size is equal to number of items
+if constexpr (!std::is_void_v)
+this->mCurrentSize += ValueSize()(value);
+}
+
+void removeSize(const Value& value)
+{
+// by default total size is equal to number of items
+if constexpr (!std::is_void_v)
+{
+size_t itemSize = ValueSize()(value);
+assert(itemSize <= this->mCurrentSize);
+this->mCurrentSize -= itemSize;
+}
+}
+
+void removeOldestItem()
+{
+removeSize(mLruList.back().second);
+// remove from map
+mLruMap.erase(mLruList.back().first);
+// remove from list
+mLruList.pop_back();
+}
+
+void checkLRUItemInsert()
 {
-if (mLruMap.size() > mMaxSize)
+if constexpr (std::is_void_v)
+{ // One added, so it's enough to remove one, if needed.
+if (mLruMap.size() > mMaxSize)
+removeOldestItem();
+}
+else
 {
-// remove from map
-mLruMap.erase(mLruList.back().first);
-// remove from list
-mLruList.pop_back();
+// This must leave at least one item (it's called from insert).
+while (this->mCurrentSize > mMaxSize && mLruList.size() > 1)
+removeOldestItem();
+}
+}
+
+void checkLRUItemUpdate()
+{
+// Item update does not change total size by default.
+if constexpr (!std::is_void_v)
+{
+// This must leave at least one item (it's called from insert).
+while (this->mCurrentSize > mMaxSize && mLruList.size() > 1)
+removeOldestItem();
+}
+}
+
+void checkLRUMaxSize()
+{
+if constexpr (std::is_void_v)
+{
+while 

[Libreoffice-commits] core.git: include/o3tl

2022-04-15 Thread Stephan Bergmann (via logerrit)
 include/o3tl/string_view.hxx |8 
 1 file changed, 8 insertions(+)

New commits:
commit d7480ed72d225ee1b2b9a6ec996eeeb7a18c98a8
Author: Stephan Bergmann 
AuthorDate: Thu Apr 14 23:05:42 2022 +0200
Commit: Stephan Bergmann 
CommitDate: Fri Apr 15 08:39:01 2022 +0200

Add some clarifying comments for o3tl::getToken overloads

Change-Id: Ia81b11b659f6045f9e474b3a32b72e2c5242a80b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133057
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/o3tl/string_view.hxx b/include/o3tl/string_view.hxx
index 903cc5ced758..2438500768fe 100644
--- a/include/o3tl/string_view.hxx
+++ b/include/o3tl/string_view.hxx
@@ -74,6 +74,11 @@ inline std::basic_string_view 
getToken(std::basic_string_view(sv, delimiter, position);
@@ -133,6 +138,9 @@ inline std::basic_string_view 
getToken(std::basic_string_view();
 }
+// The following two overloads prevent deduction failures that would occur 
with their template
+// counterpart, when sv is of a type that is implicitly convertible to 
basic_string_view (like
+// OString or OUString):
 inline std::string_view getToken(std::string_view sv, sal_Int32 nToken, char 
cTok,
  sal_Int32& rnIndex)
 {


[Libreoffice-commits] core.git: include/o3tl

2022-04-14 Thread Stephan Bergmann (via logerrit)
 include/o3tl/string_view.hxx |   16 
 1 file changed, 12 insertions(+), 4 deletions(-)

New commits:
commit 7582286258984d790274295aea1cd7eb6ad96602
Author: Stephan Bergmann 
AuthorDate: Thu Apr 14 14:17:50 2022 +0200
Commit: Stephan Bergmann 
CommitDate: Thu Apr 14 22:35:39 2022 +0200

Add some clarifying comments for o3lt::getToken

Change-Id: I417f048cdcd74e0a06b4c08d7d1851ea3e8a7077
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133015
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/o3tl/string_view.hxx b/include/o3tl/string_view.hxx
index bf72c0b2b976..903cc5ced758 100644
--- a/include/o3tl/string_view.hxx
+++ b/include/o3tl/string_view.hxx
@@ -48,9 +48,13 @@ inline int compareToIgnoreAsciiCase(std::u16string_view s1, 
std::u16string_view
 return rtl_ustr_compareIgnoreAsciiCase_WithLength(s1.data(), s1.size(), 
s2.data(), s2.size());
 };
 
-// Similar to O[U]String::getToken, returning the first token of a 
std::[u16]string_view, starting
-// at a given position (and if needed, it can be extended to return the n'th 
token instead of just
-// the first, or support an initial position of npos):
+// Similar to O[U]String::getToken, returning the first token of a 
std::[u16]string_view starting
+// at a given position.
+//
+// Attention:  There are two sets of o3tl::getToken overloads here.  This 
first set has an interface
+// based on std::size_t length parameters, and its semantics don't match those 
of
+// O[U]String::getToken exactly (buf if needed, it can be extended to return 
the n'th token instead
+// of just the first, and/or support an initial position of npos, to make the 
semantics match).
 template >
 inline std::basic_string_view 
getToken(std::basic_string_view sv,
   charT delimiter, 
std::size_t& position)
@@ -80,7 +84,11 @@ inline std::u16string_view getToken(std::u16string_view sv, 
char16_t delimiter,
 return getToken(sv, delimiter, position);
 }
 
-// Similar to OUString::getToken
+// Similar to O[U]String::getToken.
+//
+// Attention:  There are two sets of o3tl::getToken overloads here.  This 
second set has an
+// interface based on sal_Int32 length parameters, and is meant to be a 
drop-in replacement for
+// O[U]String::getToken.
 template >
 inline std::basic_string_view 
getToken(std::basic_string_view pStr,
   sal_Int32 nToken, charT 
cTok,


[Libreoffice-commits] core.git: include/o3tl

2022-04-14 Thread Stephan Bergmann (via logerrit)
 include/o3tl/string_view.hxx |5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

New commits:
commit 871adb006645d0fd5eeecab70ea4c937de85c38e
Author: Stephan Bergmann 
AuthorDate: Thu Apr 14 11:00:36 2022 +0200
Commit: Stephan Bergmann 
CommitDate: Thu Apr 14 13:29:41 2022 +0200

Fix comment again

...which had been butchered by c7fb93764b321e5bf4cd143dd0c29be60de6d8f8 
"Cleanup
comment":  e4ff847fe0796420ba8023b70cad8589f5f19e9f "loplugin:stringview 
check
for getToken and trim" had turned this into a template, but had not lifted 
the
other restrictions.  But while at it, also adapt the mention of "OString" 
and
"std::string_view" in the comment to that
e4ff847fe0796420ba8023b70cad8589f5f19e9f change.

Change-Id: I3c27efe145c4bea6c4b16f81da671bf22160545c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133000
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/o3tl/string_view.hxx b/include/o3tl/string_view.hxx
index dec21bd70338..eb98e243c8b1 100644
--- a/include/o3tl/string_view.hxx
+++ b/include/o3tl/string_view.hxx
@@ -48,8 +48,9 @@ inline int compareToIgnoreAsciiCase(std::u16string_view s1, 
std::u16string_view
 return rtl_ustr_compareIgnoreAsciiCase_WithLength(s1.data(), s1.size(), 
s2.data(), s2.size());
 };
 
-// Similar to OString::getToken, returning the first token of a 
std::string_view, starting at a
-// given position:
+// Similar to O[U]String::getToken, returning the first token of a 
std::[u16]string_view, starting
+// at a given position (and if needed, it can be extended to return the n'th 
token instead of just
+// the first, or support an initial position of npos):
 template >
 inline std::basic_string_view 
getToken(std::basic_string_view sv,
   charT delimiter, 
std::size_t& position)


[Libreoffice-commits] core.git: include/o3tl

2022-04-11 Thread Mike Kaganski (via logerrit)
 include/o3tl/string_view.hxx |4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

New commits:
commit c7fb93764b321e5bf4cd143dd0c29be60de6d8f8
Author: Mike Kaganski 
AuthorDate: Mon Apr 11 10:13:16 2022 +0300
Commit: Mike Kaganski 
CommitDate: Mon Apr 11 12:06:53 2022 +0200

Cleanup comment

... after commit e4ff847fe0796420ba8023b70cad8589f5f19e9f already
made it a template.

Change-Id: Ia433150cb1f9909906ceb986c50d4334cc2b1897
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132806
Tested-by: Jenkins
Reviewed-by: Mike Kaganski 

diff --git a/include/o3tl/string_view.hxx b/include/o3tl/string_view.hxx
index 2a33885ce166..5d3c7fcc43e2 100644
--- a/include/o3tl/string_view.hxx
+++ b/include/o3tl/string_view.hxx
@@ -38,9 +38,7 @@ inline int compareToIgnoreAsciiCase(std::u16string_view s1, 
std::u16string_view
 };
 
 // Similar to OString::getToken, returning the first token of a 
std::string_view, starting at a
-// given position (and if needed, it can be turned into a template to also 
cover std::u16string_view
-// etc., or extended to return the n'th token instead of just the first, or 
support an initial
-// position of npos):
+// given position:
 template >
 inline std::basic_string_view 
getToken(std::basic_string_view sv,
   charT delimiter, 
std::size_t& position)


[Libreoffice-commits] core.git: include/o3tl include/rtl

2022-04-11 Thread Mike Kaganski (via logerrit)
 include/o3tl/string_view.hxx |   12 ++--
 include/rtl/ustring.h|2 +-
 include/rtl/ustring.hxx  |2 +-
 3 files changed, 8 insertions(+), 8 deletions(-)

New commits:
commit b9caa1c0732868903dac7ba70c4092d0213235b6
Author: Mike Kaganski 
AuthorDate: Mon Apr 11 10:02:49 2022 +0300
Commit: Mike Kaganski 
CommitDate: Mon Apr 11 10:35:11 2022 +0200

Replace references to rtl_ImplIsWhitespace with implIsWhitespace

... after commit 57f22d9b1a4e1cd161a35c8e4c390661db981d2c.

Change-Id: I4232adc805593575d0bb7549b40ad35308829261
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132805
Tested-by: Jenkins
Reviewed-by: Mike Kaganski 

diff --git a/include/o3tl/string_view.hxx b/include/o3tl/string_view.hxx
index c09352145440..2a33885ce166 100644
--- a/include/o3tl/string_view.hxx
+++ b/include/o3tl/string_view.hxx
@@ -317,8 +317,8 @@ constexpr bool ends_with(std::u16string_view sv, 
std::u16string_view x,
 
 namespace internal
 {
-// copy of rtl_ImplIsWhitespace from sal/rtl/strimp.cxx
-inline bool rtl_ImplIsWhitespace(sal_Unicode c)
+// copy of implIsWhitespace from sal/rtl/strtmpl.hxx
+inline bool implIsWhitespace(sal_Unicode c)
 {
 /* Space or Control character? */
 if ((c <= 32) && c)
@@ -346,10 +346,10 @@ inline std::u16string_view trim(std::u16string_view str)
 sal_Int32 nPostSpaces = 0;
 sal_Int32 nIndex = str.size() - 1;
 
-while ((nPreSpaces < nLen) && internal::rtl_ImplIsWhitespace(*(str.data() 
+ nPreSpaces)))
+while ((nPreSpaces < nLen) && internal::implIsWhitespace(*(str.data() + 
nPreSpaces)))
 nPreSpaces++;
 
-while ((nIndex > nPreSpaces) && 
internal::rtl_ImplIsWhitespace(*(str.data() + nIndex)))
+while ((nIndex > nPreSpaces) && internal::implIsWhitespace(*(str.data() + 
nIndex)))
 {
 nPostSpaces++;
 nIndex--;
@@ -368,10 +368,10 @@ inline std::string_view trim(std::string_view str)
 sal_Int32 nPostSpaces = 0;
 sal_Int32 nIndex = str.size() - 1;
 
-while ((nPreSpaces < nLen) && internal::rtl_ImplIsWhitespace(*(str.data() 
+ nPreSpaces)))
+while ((nPreSpaces < nLen) && internal::implIsWhitespace(*(str.data() + 
nPreSpaces)))
 nPreSpaces++;
 
-while ((nIndex > nPreSpaces) && 
internal::rtl_ImplIsWhitespace(*(str.data() + nIndex)))
+while ((nIndex > nPreSpaces) && internal::implIsWhitespace(*(str.data() + 
nIndex)))
 {
 nPostSpaces++;
 nIndex--;
diff --git a/include/rtl/ustring.h b/include/rtl/ustring.h
index 16ec6ed5931c..2371d9a5e8d7 100644
--- a/include/rtl/ustring.h
+++ b/include/rtl/ustring.h
@@ -2094,7 +2094,7 @@ SAL_DLLPUBLIC void SAL_CALL 
rtl_uString_newToAsciiUpperCase(
 The new string results from removing all characters with values less than
 or equal to 32 (the space character), and also Unicode General Punctuation
 area Space and some Control characters, form both ends of str (see
-rtl_ImplIsWhitespace).
+implIsWhitespace).
 
 This function cannot be used for language-specific conversion.  The new
 string does not necessarily have a reference count of 1 (in cases where
diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index c530f1702a81..ca061328d5a4 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -2652,7 +2652,7 @@ public:
   All characters that have codes less than or equal to
   32 (the space character), and Unicode General Punctuation area Space
   and some Control characters are considered to be white space (see
-  rtl_ImplIsWhitespace).
+  implIsWhitespace).
   If the string doesn't contain white spaces at both ends,
   then the new string is assigned with str.
 


[Libreoffice-commits] core.git: include/o3tl lotuswordpro/source

2022-03-16 Thread psidiumcode (via logerrit)
 include/o3tl/unit_conversion.hxx   |2 +-
 lotuswordpro/source/filter/lwpsilverbullet.hxx |2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

New commits:
commit 5b320aa058504becae6ac6746926b481b326a24d
Author: psidiumcode 
AuthorDate: Tue Mar 15 21:43:46 2022 +0200
Commit: Hossein 
CommitDate: Wed Mar 16 09:13:23 2022 +0100

tdf#147021 Use std::size() instead of SAL_N_ELEMENTS() macro

Change-Id: Ia711e939f769c6a2257bd1fb3607b315f931a0ca
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131634
Tested-by: Jenkins
Reviewed-by: Hossein 

diff --git a/include/o3tl/unit_conversion.hxx b/include/o3tl/unit_conversion.hxx
index 7f67882f7e3d..67830f0d16d7 100644
--- a/include/o3tl/unit_conversion.hxx
+++ b/include/o3tl/unit_conversion.hxx
@@ -179,7 +179,7 @@ constexpr m_and_d mdBaseLen[] = {
 { 254 * 210, 10 * 1440 }, // ch => mm
 { 254 * 312, 10 * 1440 }, // line => mm
 };
-static_assert(SAL_N_ELEMENTS(mdBaseLen) == static_cast(Length::count),
+static_assert(std::size(mdBaseLen) == static_cast(Length::count),
   "mdBaseL must have an entry for each unit in o3tl::Length");
 
 // The resulting multipliers and divisors array
diff --git a/lotuswordpro/source/filter/lwpsilverbullet.hxx 
b/lotuswordpro/source/filter/lwpsilverbullet.hxx
index 5c2f51247b31..8c68a960eedc 100644
--- a/lotuswordpro/source/filter/lwpsilverbullet.hxx
+++ b/lotuswordpro/source/filter/lwpsilverbullet.hxx
@@ -149,7 +149,7 @@ private:
 inline const OUString& LwpSilverBullet::GetBulletStyleName() const { return 
m_strStyleName; }
 inline bool LwpSilverBullet::IsLesserLevel(sal_uInt16 nPos)
 {
-if (nPos < SAL_N_ELEMENTS(m_pResetPositionFlags))
+if (nPos < std::size(m_pResetPositionFlags))
 return ((m_pResetPositionFlags[nPos] & LESSERLEVEL) != 0);
 return false;
 }


[Libreoffice-commits] core.git: include/o3tl sc/source

2022-03-07 Thread Luboš Luňák (via logerrit)
 include/o3tl/sorted_vector.hxx   |   57 +++
 sc/source/filter/inc/sheetdatabuffer.hxx |9 
 sc/source/filter/oox/sheetdatabuffer.cxx |   12 +-
 3 files changed, 64 insertions(+), 14 deletions(-)

New commits:
commit 6810aa937caca167a6dc1aa0ac63d5995a143b10
Author: Luboš Luňák 
AuthorDate: Sun Mar 6 19:24:37 2022 +0100
Commit: Luboš Luňák 
CommitDate: Mon Mar 7 10:40:20 2022 +0100

faster bulk insert into o3tl::sorted_vector (tdf#117366)

Repeated insert() into o3tl::sorted_vector can turn out to be
pathological, repeatedly moving most items aside for each
element inserted. Make it possible to insert a normal vector
that's been pre-sorted and made unique. 31s->9s for loading
tdf#117366.

Change-Id: If3a0366dd240ad46c23f5f3dc04e781b8c4b2aa2
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131085
Tested-by: Jenkins
Reviewed-by: Luboš Luňák 

diff --git a/include/o3tl/sorted_vector.hxx b/include/o3tl/sorted_vector.hxx
index 2bd8b7273a9a..13c0b25f8f0e 100644
--- a/include/o3tl/sorted_vector.hxx
+++ b/include/o3tl/sorted_vector.hxx
@@ -12,7 +12,9 @@
 
 #include 
 #include 
+#include 
 #include 
+#include 
 #include 
 #include 
 
@@ -229,19 +231,32 @@ public:
 
 void insert(sorted_vector const& rOther)
 {
-   // optimization for the rather common case that we are overwriting this 
with the contents
-   // of another sorted vector
-   if ( empty() )
-   {
-   m_vector.insert(m_vector.begin(), rOther.m_vector.begin(), 
rOther.m_vector.end());
-   }
-   else
-   {
-   for (const_iterator it = rOther.m_vector.begin(); it != 
rOther.m_vector.end(); ++it)
-   {
-   insert(*it);
-   }
-   }
+// optimization for the rather common case that we are overwriting 
this with the contents
+// of another sorted vector
+if ( empty() )
+m_vector.insert(m_vector.begin(), rOther.m_vector.begin(), 
rOther.m_vector.end());
+else
+insert_internal( rOther.m_vector );
+}
+
+void insert_sorted_unique_vector(const std::vector& rOther)
+{
+assert( std::is_sorted(rOther.begin(), rOther.end(), Compare()));
+assert( std::unique(rOther.begin(), rOther.end(), compare_equal) == 
rOther.end());
+if ( empty() )
+m_vector.insert(m_vector.begin(), rOther.m_vector.begin(), 
rOther.m_vector.end());
+else
+insert_internal( rOther );
+}
+
+void insert_sorted_unique_vector(std::vector&& rOther)
+{
+assert( std::is_sorted(rOther.begin(), rOther.end(), Compare()));
+assert( std::unique(rOther.begin(), rOther.end(), compare_equal) == 
rOther.end());
+if ( empty() )
+m_vector.swap( rOther );
+else
+insert_internal( rOther );
 }
 
 /* Clear() elements in the vector, and free them one by one. */
@@ -266,6 +281,22 @@ public:
 }
 
 private:
+static bool compare_equal( const Value& v1, const Value& v2 )
+{   // Synthetize == check from < check for std::unique asserts above.
+return !Compare()( v1, v2 ) && !Compare()( v2, v1 );
+}
+
+void insert_internal( const std::vector& rOther )
+{
+// Do a union in one pass rather than repeated insert() that could 
repeatedly
+// move large amounts of data.
+vector_t tmp;
+tmp.reserve( m_vector.size() + rOther.size());
+std::set_union( m_vector.begin(), m_vector.end(),
+rOther.begin(), rOther.end(),
+std::back_inserter( tmp ), Compare());
+m_vector.swap( tmp );
+}
 
 vector_t m_vector;
 };
diff --git a/sc/source/filter/inc/sheetdatabuffer.hxx 
b/sc/source/filter/inc/sheetdatabuffer.hxx
index a673f91b66ec..7f4930bff450 100644
--- a/sc/source/filter/inc/sheetdatabuffer.hxx
+++ b/sc/source/filter/inc/sheetdatabuffer.hxx
@@ -201,8 +201,17 @@ private:
 return lhs.mnEndRow 
RowStyles;
 typedef ::std::map< sal_Int32, RowStyles > ColStyles;
+typedef ::std::vector< RowRangeStyle > TmpRowStyles;
+typedef ::std::map< sal_Int32, TmpRowStyles > TmpColStyles;
 /** Stores information about a merged cell range. */
 struct MergedRange
 {
diff --git a/sc/source/filter/oox/sheetdatabuffer.cxx 
b/sc/source/filter/oox/sheetdatabuffer.cxx
index d4d0ad87affd..b4d6158f66fe 100644
--- a/sc/source/filter/oox/sheetdatabuffer.cxx
+++ b/sc/source/filter/oox/sheetdatabuffer.cxx
@@ -353,6 +353,9 @@ void SheetDataBuffer::addColXfStyles()
 addIfNotInMyMap( getStyles(), rangeStyleListMap, rFormatKeyPair.first, 
rFormatKeyPair.second, rRangeList );
 }
 // gather all ranges that have the same style and apply them in bulk
+// Collect data in unsorted vectors and sort them just once at the end
+// instead of possibly slow repeated inserts.
+TmpColStyles tmpStylesPerColumn;
 for 

[Libreoffice-commits] core.git: include/o3tl

2022-03-02 Thread Caolán McNamara (via logerrit)
 include/o3tl/deleter.hxx |1 +
 1 file changed, 1 insertion(+)

New commits:
commit 6b6c9fc67cdd42fa8feb3d7c4f6346ed54d4619c
Author: Caolán McNamara 
AuthorDate: Wed Mar 2 16:16:15 2022 +
Commit: Caolán McNamara 
CommitDate: Wed Mar 2 20:51:31 2022 +0100

cid#1500437 silence Resource leak

Change-Id: Ibaa402dea5c684a08e2fe8ca8425ea92332bba9d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130887
Tested-by: Caolán McNamara 
Reviewed-by: Caolán McNamara 

diff --git a/include/o3tl/deleter.hxx b/include/o3tl/deleter.hxx
index 96f9b4b49274..76d8d5a357fd 100644
--- a/include/o3tl/deleter.hxx
+++ b/include/o3tl/deleter.hxx
@@ -58,6 +58,7 @@ template  void 
reset_preserve_ptr_during(uniqueptr& ptr)
 // e.g. SdrObject::GetBroadcaster() is called during the destructor
 // in SdrEdgeObj::Notify(). So delete first, then clear the pointer
 delete ptr.get();
+// coverity[leaked_storage] - not a leak, deleted on line above
 (void)ptr.release();
 }
 }


[Libreoffice-commits] core.git: include/o3tl include/rtl o3tl/qa

2022-03-01 Thread Luboš Luňák (via logerrit)
 include/o3tl/string_view.hxx |7 ++-
 include/rtl/ustring.hxx  |4 
 o3tl/qa/test-string_view.cxx |8 
 3 files changed, 18 insertions(+), 1 deletion(-)

New commits:
commit ffe7850a1449c43dd077c5cb073d8eee178f7099
Author: Luboš Luňák 
AuthorDate: Tue Mar 1 10:44:12 2022 +0100
Commit: Luboš Luňák 
CommitDate: Tue Mar 1 18:00:17 2022 +0100

fix o3tl::equalsIgnoreAsciiCase()

As the OUString equivalent shows, it needs to check == 0. Commit
33ecd0d5c4fff9511a8436513936a3f7044a775a for some reason also
dropped the cheap checks (even from OUString) that OString has,
so add them.

Change-Id: I88e68b5ae10fd76c3c08b9b36d5abed0fad17bbf
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130753
Reviewed-by: Stephan Bergmann 
Reviewed-by: Luboš Luňák 
Tested-by: Jenkins

diff --git a/include/o3tl/string_view.hxx b/include/o3tl/string_view.hxx
index 0ca26a829932..74f15bf33b54 100644
--- a/include/o3tl/string_view.hxx
+++ b/include/o3tl/string_view.hxx
@@ -23,7 +23,12 @@ namespace o3tl
 // Like OUString::equalsIgnoreAsciiCase, but for two std::u16string_view:
 inline bool equalsIgnoreAsciiCase(std::u16string_view s1, std::u16string_view 
s2)
 {
-return rtl_ustr_compareIgnoreAsciiCase_WithLength(s1.data(), s1.size(), 
s2.data(), s2.size());
+if (s1.size() != s2.size())
+return false;
+if (s1.data() == s2.data())
+return true;
+return rtl_ustr_compareIgnoreAsciiCase_WithLength(s1.data(), s1.size(), 
s2.data(), s2.size())
+   == 0;
 };
 
 // Similar to OString::getToken, returning the first token of a 
std::string_view, starting at a
diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index cad257caeb58..4d983a089f72 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -977,6 +977,10 @@ public:
 */
 #if defined LIBO_INTERNAL_ONLY
 bool equalsIgnoreAsciiCase(std::u16string_view sv) const {
+if ( sal_uInt32(pData->length) != sv.size() )
+return false;
+if ( pData->buffer == sv.data() )
+return true;
 return
 rtl_ustr_compareIgnoreAsciiCase_WithLength(
 pData->buffer, pData->length, sv.data(), sv.size())
diff --git a/o3tl/qa/test-string_view.cxx b/o3tl/qa/test-string_view.cxx
index b400c9605962..c068638f800e 100644
--- a/o3tl/qa/test-string_view.cxx
+++ b/o3tl/qa/test-string_view.cxx
@@ -60,6 +60,7 @@ private:
 CPPUNIT_TEST(testStartsWithRest);
 CPPUNIT_TEST(testEndsWith);
 CPPUNIT_TEST(testEndsWithRest);
+CPPUNIT_TEST(testEqualsIgnoreAsciiCase);
 CPPUNIT_TEST_SUITE_END();
 
 void testStartsWith()
@@ -585,6 +586,13 @@ private:
 CPPUNIT_ASSERT_EQUAL(u""sv, rest);
 }
 }
+
+void testEqualsIgnoreAsciiCase()
+{
+using namespace std::string_view_literals;
+CPPUNIT_ASSERT(o3tl::equalsIgnoreAsciiCase(u"test"sv, u"test"sv));
+CPPUNIT_ASSERT(!o3tl::equalsIgnoreAsciiCase(u"test"sv, u"test2"sv));
+}
 };
 
 CPPUNIT_TEST_SUITE_REGISTRATION(Test);


[Libreoffice-commits] core.git: include/o3tl

2022-02-28 Thread Stephan Bergmann (via logerrit)
 include/o3tl/unreachable.hxx |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

New commits:
commit 8597748c42727b62e60f8a4af45520193d682de0
Author: Stephan Bergmann 
AuthorDate: Mon Feb 28 21:14:11 2022 +0100
Commit: Stephan Bergmann 
CommitDate: Mon Feb 28 22:54:38 2022 +0100

Brown paper bag fix

...of 87369ad7b82da6904e889614c88617e610d4506b "Use std::unreachable if
available".  (Unfortunately, Clang didn't warn about the thus meaningless 
uses
of O3TL_UNREACHABLE, presumably due to


"Suppress all -Wunused-value warnings from macro body expansions.")

(While at it, and as the expansion of O3TL_UNREACHABLE is now a nice full
expression, wrap it in parentheses, as is common best practice for such 
macro
definitions.)

Change-Id: I555e6716ebb66172add686521446d90db6054845
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130729
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/o3tl/unreachable.hxx b/include/o3tl/unreachable.hxx
index d5a2e156b760..604f7a2f7728 100644
--- a/include/o3tl/unreachable.hxx
+++ b/include/o3tl/unreachable.hxx
@@ -21,7 +21,7 @@
 
 #if defined __cpp_lib_unreachable
 
-#define O3TL_UNREACHABLE ::std::unreachable
+#define O3TL_UNREACHABLE (::std::unreachable())
 
 #else
 


[Libreoffice-commits] core.git: include/o3tl

2022-02-28 Thread Stephan Bergmann (via logerrit)
 include/o3tl/unreachable.hxx |   19 ++-
 1 file changed, 14 insertions(+), 5 deletions(-)

New commits:
commit 87369ad7b82da6904e889614c88617e610d4506b
Author: Stephan Bergmann 
AuthorDate: Mon Feb 28 08:03:06 2022 +0100
Commit: Stephan Bergmann 
CommitDate: Mon Feb 28 09:38:07 2022 +0100

Use std::unreachable if available

Change-Id: I686e36cf3e77a94293ef6923ba00181eb3e02c81
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130661
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/o3tl/unreachable.hxx b/include/o3tl/unreachable.hxx
index bc33d34b534e..d5a2e156b760 100644
--- a/include/o3tl/unreachable.hxx
+++ b/include/o3tl/unreachable.hxx
@@ -13,12 +13,19 @@
 #include 
 
 #include 
+#include 
 
-// A better replacement for assert(false) to indicate a place in the code that 
should not be
-// reachable.  This should improve on the sometimes poor false-positive 
warnings emitted by
-// compilers when they cannot detect that some condition flagged by 
assert(false) cannot occur,
-// either because assert is reduced to a no-op by NDEBUG or because assert is 
not marked as noreturn
-// in the MSVC headers.  This is inspired by LLVM's LLVM_BUILTIN_UNREACHABLE
+// An approximation of C++23 std::unreachable
+// ( 
"Function to mark
+// unreachable code").
+
+#if defined __cpp_lib_unreachable
+
+#define O3TL_UNREACHABLE ::std::unreachable
+
+#else
+
+// This fallback implementation is inspired by LLVM's LLVM_BUILTIN_UNREACHABLE
 // (llvm/include/llvm/Support/Compiler.h).
 
 #if defined _MSC_VER
@@ -36,4 +43,6 @@
 
 #endif
 
+#endif
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */


[Libreoffice-commits] core.git: include/o3tl

2022-02-04 Thread Caolán McNamara (via logerrit)
 include/o3tl/unit_conversion.hxx |   14 ++
 1 file changed, 10 insertions(+), 4 deletions(-)

New commits:
commit f2d62b11cd7d47925fd098b3947726313d6b296e
Author: Caolán McNamara 
AuthorDate: Thu Feb 3 09:43:32 2022 +
Commit: Caolán McNamara 
CommitDate: Fri Feb 4 11:20:38 2022 +0100

cid#1497934 silence Division or modulo by zero

Change-Id: I2f894e46b962adfc9a5c97dc6731d292a61939a4
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129405
Tested-by: Jenkins
Reviewed-by: Caolán McNamara 

diff --git a/include/o3tl/unit_conversion.hxx b/include/o3tl/unit_conversion.hxx
index c1961ca2feb8..7f67882f7e3d 100644
--- a/include/o3tl/unit_conversion.hxx
+++ b/include/o3tl/unit_conversion.hxx
@@ -107,14 +107,21 @@ constexpr sal_Int64 MulDivSaturate(I n, sal_Int64 m, 
sal_Int64 d)
 return MulDiv(n, m, d);
 }
 
+template  constexpr std::common_type_t asserting_gcd(M 
m, N n)
+{
+auto ret = std::gcd(m, n);
+assert(ret != 0);
+return ret;
+}
+
 // Packs integral multiplier and divisor for conversion from one unit to 
another
 struct m_and_d
 {
 sal_Int64 m; // multiplier
 sal_Int64 d; // divisor
 constexpr m_and_d(sal_Int64 _m, sal_Int64 _d)
-: m(_m / std::gcd(_m, _d)) // make sure to use smallest quotients here 
because
-, d(_d / std::gcd(_m, _d)) // they will be multiplied when building 
final table
+: m(_m / asserting_gcd(_m, _d)) // make sure to use smallest quotients 
here because
+, d(_d / asserting_gcd(_m, _d)) // they will be multiplied when 
building final table
 {
 assert(_m > 0 && _d > 0);
 }
@@ -134,8 +141,7 @@ template  constexpr auto prepareMDArray(const 
m_and_d ()[N])
 assert(mdBase[i].m < SAL_MAX_INT64 / mdBase[j].d);
 assert(mdBase[i].d < SAL_MAX_INT64 / mdBase[j].m);
 const sal_Int64 m = mdBase[i].m * mdBase[j].d, d = mdBase[i].d * 
mdBase[j].m;
-const sal_Int64 g = std::gcd(m, d);
-assert(g != 0);
+const sal_Int64 g = asserting_gcd(m, d);
 a[i][j] = m / g;
 a[j][i] = d / g;
 }


[Libreoffice-commits] core.git: include/o3tl

2022-02-03 Thread Caolán McNamara (via logerrit)
 include/o3tl/unit_conversion.hxx |1 +
 1 file changed, 1 insertion(+)

New commits:
commit 50f4b6bfd5c71a66d0c50aad7a99408ce1b99d58
Author: Caolán McNamara 
AuthorDate: Thu Feb 3 09:37:24 2022 +
Commit: Caolán McNamara 
CommitDate: Thu Feb 3 15:44:26 2022 +0100

cid#1497935 silence Division or modulo by zero

Change-Id: I60fc87d0724d8b677479c107af4f3cef4ef47186
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129401
Tested-by: Jenkins
Reviewed-by: Caolán McNamara 

diff --git a/include/o3tl/unit_conversion.hxx b/include/o3tl/unit_conversion.hxx
index 27fb184d52a4..c1961ca2feb8 100644
--- a/include/o3tl/unit_conversion.hxx
+++ b/include/o3tl/unit_conversion.hxx
@@ -135,6 +135,7 @@ template  constexpr auto prepareMDArray(const 
m_and_d ()[N])
 assert(mdBase[i].d < SAL_MAX_INT64 / mdBase[j].m);
 const sal_Int64 m = mdBase[i].m * mdBase[j].d, d = mdBase[i].d * 
mdBase[j].m;
 const sal_Int64 g = std::gcd(m, d);
+assert(g != 0);
 a[i][j] = m / g;
 a[j][i] = d / g;
 }


[Libreoffice-commits] core.git: include/o3tl sc/inc sc/source vcl/source xmlsecurity/qa

2021-11-23 Thread Mike Kaganski (via logerrit)
 include/o3tl/typed_flags_set.hxx|   96 
 include/o3tl/underlyingenumvalue.hxx|3 -
 sc/inc/address.hxx  |4 -
 sc/source/core/tool/address.cxx |2 
 sc/source/core/tool/reffind.cxx |2 
 vcl/source/animate/AnimationBitmap.cxx  |2 
 xmlsecurity/qa/unit/signing/signing.cxx |   28 -
 7 files changed, 69 insertions(+), 68 deletions(-)

New commits:
commit e41024bc9a693164ffc64048046469aaa81a07d4
Author: Mike Kaganski 
AuthorDate: Wed Nov 24 00:00:21 2021 +0300
Commit: Mike Kaganski 
CommitDate: Wed Nov 24 05:30:53 2021 +0100

Rename o3tl::underlyingEnumValue to o3tl::to_underlying to match C++23

Change-Id: I1597a8e77199445bf377dbe54adc3134bb04fd51
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125748
Tested-by: Jenkins
Reviewed-by: Mike Kaganski 

diff --git a/include/o3tl/typed_flags_set.hxx b/include/o3tl/typed_flags_set.hxx
index 7c9053bcd4f0..413ee9579d4d 100644
--- a/include/o3tl/typed_flags_set.hxx
+++ b/include/o3tl/typed_flags_set.hxx
@@ -104,10 +104,10 @@ template
 constexpr typename o3tl::typed_flags::Wrap operator ~(E rhs) {
 assert(
 o3tl::detail::isNonNegative(
-o3tl::underlyingEnumValue(rhs)));
+o3tl::to_underlying(rhs)));
 return static_cast::Wrap>(
 o3tl::typed_flags::mask
-& ~o3tl::underlyingEnumValue(rhs));
+& ~o3tl::to_underlying(rhs));
 }
 
 template constexpr typename o3tl::typed_flags::Wrap operator ~(
@@ -115,7 +115,7 @@ template constexpr typename 
o3tl::typed_flags::Wrap operator ~(
 {
 return static_cast::Wrap>(
 o3tl::typed_flags::mask
-& ~o3tl::underlyingEnumValue(rhs));
+& ~o3tl::to_underlying(rhs));
 }
 
 template constexpr typename o3tl::typed_flags::Wrap operator ^(
@@ -123,13 +123,13 @@ template constexpr typename 
o3tl::typed_flags::Wrap operator ^(
 {
 assert(
 o3tl::detail::isNonNegative(
-o3tl::underlyingEnumValue(lhs)));
+o3tl::to_underlying(lhs)));
 assert(
 o3tl::detail::isNonNegative(
-o3tl::underlyingEnumValue(rhs)));
+o3tl::to_underlying(rhs)));
 return static_cast::Wrap>(
-o3tl::underlyingEnumValue(lhs)
-^ o3tl::underlyingEnumValue(rhs));
+o3tl::to_underlying(lhs)
+^ o3tl::to_underlying(rhs));
 }
 
 template constexpr typename o3tl::typed_flags::Wrap operator ^(
@@ -137,10 +137,10 @@ template constexpr typename 
o3tl::typed_flags::Wrap operator ^(
 {
 assert(
 o3tl::detail::isNonNegative(
-o3tl::underlyingEnumValue(lhs)));
+o3tl::to_underlying(lhs)));
 return static_cast::Wrap>(
-o3tl::underlyingEnumValue(lhs)
-^ o3tl::underlyingEnumValue(rhs));
+o3tl::to_underlying(lhs)
+^ o3tl::to_underlying(rhs));
 }
 
 template constexpr typename o3tl::typed_flags::Wrap operator ^(
@@ -148,10 +148,10 @@ template constexpr typename 
o3tl::typed_flags::Wrap operator ^(
 {
 assert(
 o3tl::detail::isNonNegative(
-o3tl::underlyingEnumValue(rhs)));
+o3tl::to_underlying(rhs)));
 return static_cast::Wrap>(
-o3tl::underlyingEnumValue(lhs)
-^ o3tl::underlyingEnumValue(rhs));
+o3tl::to_underlying(lhs)
+^ o3tl::to_underlying(rhs));
 }
 
 template constexpr
@@ -159,21 +159,21 @@ typename o3tl::typed_flags::Wrap operator ^(
 W lhs, W rhs)
 {
 return static_cast(
-o3tl::underlyingEnumValue(lhs)
-^ o3tl::underlyingEnumValue(rhs));
+o3tl::to_underlying(lhs)
+^ o3tl::to_underlying(rhs));
 }
 
 template
 constexpr typename o3tl::typed_flags::Wrap operator &(E lhs, E rhs) {
 assert(
 o3tl::detail::isNonNegative(
-o3tl::underlyingEnumValue(lhs)));
+o3tl::to_underlying(lhs)));
 assert(
 o3tl::detail::isNonNegative(
-o3tl::underlyingEnumValue(rhs)));
+o3tl::to_underlying(rhs)));
 return static_cast::Wrap>(
-o3tl::underlyingEnumValue(lhs)
-& o3tl::underlyingEnumValue(rhs));
+o3tl::to_underlying(lhs)
+& o3tl::to_underlying(rhs));
 }
 
 template constexpr typename o3tl::typed_flags::Wrap operator &(
@@ -181,10 +181,10 @@ template constexpr typename 
o3tl::typed_flags::Wrap operator &(
 {
 assert(
 o3tl::detail::isNonNegative(
-o3tl::underlyingEnumValue(lhs)));
+o3tl::to_underlying(lhs)));
 return static_cast::Wrap>(
-o3tl::underlyingEnumValue(lhs)
-& o3tl::underlyingEnumValue(rhs));
+o3tl::to_underlying(lhs)
+& o3tl::to_underlying(rhs));
 }
 
 template constexpr typename o3tl::typed_flags::Wrap operator &(
@@ -192,10 +192,10 @@ template constexpr typename 
o3tl::typed_flags::Wrap operator &(
 {
 assert(
 o3tl::detail::isNonNegative(
-o3tl::underlyingEnumValue(rhs)));
+

[Libreoffice-commits] core.git: include/o3tl o3tl/CppunitTest_o3tl_tests.mk o3tl/qa

2021-09-21 Thread Stephan Bergmann (via logerrit)
 include/o3tl/string_view.hxx   |  121 
 o3tl/CppunitTest_o3tl_tests.mk |1 
 o3tl/qa/test-string_view.cxx   |  591 +
 3 files changed, 713 insertions(+)

New commits:
commit b46894e7d063cc96609c8aaea76f4a7ffc5f170f
Author: Stephan Bergmann 
AuthorDate: Tue Sep 21 22:19:06 2021 +0200
Commit: Stephan Bergmann 
CommitDate: Tue Sep 21 23:32:02 2021 +0200

Some more o3tl::starts/ends_with overloads

...including ones with a rest out parameter, modeled after their O(U)String
counterparts and not present in any C++ standard (so intended to stay in 
o3tl,
even when the C++20 wrappers are eventually removed again).  Plus test code.

These additional overloads will be used in forthcoming commits changing more
places to use std string_view.

Change-Id: Ifd05e0fdcb93e8751da22b8e4a59796ad00fe581
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122407
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/o3tl/string_view.hxx b/include/o3tl/string_view.hxx
index b66ba1175a57..4cb9790900f6 100644
--- a/include/o3tl/string_view.hxx
+++ b/include/o3tl/string_view.hxx
@@ -15,6 +15,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -107,6 +108,126 @@ constexpr bool ends_with(std::basic_string_view sv, charT const*
 return ends_with(sv, std::basic_string_view(x));
 #endif
 }
+// The following overloads prevent deduction failures that would occur with 
their template
+// counterparts, when x is of a type that is implicitly convertible to 
basic_string_view (like
+// OString or OUString, and we only bother to provide overloads for the char 
and char16_t cases, not
+// also for char32_t and wchar_t, nor for C++20 char8_t):
+constexpr bool starts_with(std::string_view sv, std::string_view x) noexcept
+{
+return starts_with(sv, x);
+}
+constexpr bool starts_with(std::u16string_view sv, std::u16string_view x) 
noexcept
+{
+return starts_with(sv, x);
+}
+constexpr bool ends_with(std::string_view sv, std::string_view x) noexcept
+{
+return ends_with(sv, x);
+}
+constexpr bool ends_with(std::u16string_view sv, std::u16string_view x) 
noexcept
+{
+return ends_with(sv, x);
+}
+
+// Variants of C++20 std::basic_string_view::starts_with and
+// std::basic_string_view::ends_with that have a rest out parameter, similar 
to our OString and
+// OUString startsWith and endsWith member functions:
+template >
+constexpr bool starts_with(std::basic_string_view sv,
+   std::basic_string_view x,
+   std::basic_string_view* rest) 
noexcept
+{
+assert(rest != nullptr);
+auto const found = starts_with(sv, x);
+if (found)
+{
+*rest = sv.substr(x.length());
+}
+return found;
+}
+template >
+constexpr bool starts_with(std::basic_string_view sv, charT x,
+   std::basic_string_view* rest) 
noexcept
+{
+assert(rest != nullptr);
+auto const found = starts_with(sv, x);
+if (found)
+{
+*rest = sv.substr(1);
+}
+return found;
+}
+template >
+constexpr bool starts_with(std::basic_string_view sv, charT 
const* x,
+   std::basic_string_view* rest)
+{
+assert(rest != nullptr);
+auto const found = starts_with(sv, x);
+if (found)
+{
+*rest = sv.substr(traits::length(x));
+}
+return found;
+}
+template >
+constexpr bool ends_with(std::basic_string_view sv,
+ std::basic_string_view x,
+ std::basic_string_view* rest) noexcept
+{
+assert(rest != nullptr);
+auto const found = ends_with(sv, x);
+if (found)
+{
+*rest = sv.substr(0, sv.length() - x.length());
+}
+return found;
+}
+template >
+constexpr bool ends_with(std::basic_string_view sv, charT x,
+ std::basic_string_view* rest) noexcept
+{
+assert(rest != nullptr);
+auto const found = ends_with(sv, x);
+if (found)
+{
+*rest = sv.substr(0, sv.length() - 1);
+}
+return found;
+}
+template >
+constexpr bool ends_with(std::basic_string_view sv, charT 
const* x,
+ std::basic_string_view* rest)
+{
+assert(rest != nullptr);
+auto const found = ends_with(sv, x);
+if (found)
+{
+*rest = sv.substr(0, sv.length() - traits::length(x));
+}
+return found;
+}
+// The following overloads prevent deduction failures that would occur with 
their template
+// counterparts, when x is of a type that is implicitly convertible to 
basic_string_view (like
+// OString or OUString, and we only bother to provide overloads for the char 
and char16_t cases, not
+// also for char32_t and wchar_t, nor for C++20 char8_t):
+constexpr bool starts_with(std::string_view sv, std::string_view x, 
std::string_view* rest) noexcept
+{
+return starts_with(sv, x, rest);
+}
+constexpr bool 

[Libreoffice-commits] core.git: include/o3tl starmath/inc starmath/source

2021-09-19 Thread Stephan Bergmann (via logerrit)
 include/o3tl/string_view.hxx|   61 +
 starmath/inc/mathml/mathmlattr.hxx  |6 ++
 starmath/source/mathml/mathmlattr.cxx   |   76 +++-
 starmath/source/mathml/mathmlimport.cxx |2 
 4 files changed, 103 insertions(+), 42 deletions(-)

New commits:
commit e6fe048ded34a322007547d4d31e32c598aa4993
Author: Stephan Bergmann 
AuthorDate: Sun Sep 19 15:11:43 2021 +0200
Commit: Stephan Bergmann 
CommitDate: Sun Sep 19 18:14:15 2021 +0200

Some more string_view use, add o3tl::starts/ends_with

...until those C++20 string_view member functions are generally available 
(the
fallback implementations are taken directly from the C++20 spec).

(In ParseMathMLAttributeLengthValue in 
starmath/source/mathml/mathmlattr.cxx,
returning nIdx + 2 instead of nIdx + 1 for the single-character u'%' case 
was
presumably a typo, but which was harmless as the return value was only 
checked
for <= 0, and has now been turned into a bool.)

Change-Id: Ib441e474c515f016a4d81bb39f7821dfe0356499
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122322
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/o3tl/string_view.hxx b/include/o3tl/string_view.hxx
index 5ebbb0b9f044..b66ba1175a57 100644
--- a/include/o3tl/string_view.hxx
+++ b/include/o3tl/string_view.hxx
@@ -13,6 +13,7 @@
 
 #include 
 #include 
+#include 
 #include 
 
 #include 
@@ -46,6 +47,66 @@ inline std::string_view getToken(std::string_view sv, char 
delimiter, std::size_
 }
 return t;
 }
+
+// Implementations of C++20 std::basic_string_view::starts_with and
+// std::basic_string_view::ends_with, until we can use those directly on all 
platforms:
+template >
+constexpr bool starts_with(std::basic_string_view sv,
+   std::basic_string_view x) noexcept
+{
+#if defined __cpp_lib_starts_ends_with
+return sv.starts_with(x);
+#else
+return sv.substr(0, x.size()) == x;
+#endif
+}
+template >
+constexpr bool starts_with(std::basic_string_view sv, charT x) 
noexcept
+{
+#if defined __cpp_lib_starts_ends_with
+return sv.starts_with(x);
+#else
+return !sv.empty() && traits::eq(sv.front(), x);
+#endif
+}
+template >
+constexpr bool starts_with(std::basic_string_view sv, charT 
const* x)
+{
+#if defined __cpp_lib_starts_ends_with
+return sv.starts_with(x);
+#else
+return starts_with(sv, std::basic_string_view(x));
+#endif
+}
+template >
+constexpr bool ends_with(std::basic_string_view sv,
+ std::basic_string_view x) noexcept
+{
+#if defined __cpp_lib_ends_ends_with
+return sv.ends_with(x);
+#else
+return sv.size() >= x.size()
+   && sv.compare(sv.size() - x.size(), std::basic_string_view::npos, x) == 0;
+#endif
+}
+template >
+constexpr bool ends_with(std::basic_string_view sv, charT x) 
noexcept
+{
+#if defined __cpp_lib_ends_ends_with
+return sv.ends_with(x);
+#else
+return !sv.empty() && traits::eq(sv.back(), x);
+#endif
+}
+template >
+constexpr bool ends_with(std::basic_string_view sv, charT 
const* x)
+{
+#if defined __cpp_lib_ends_ends_with
+return sv.ends_with(x);
+#else
+return ends_with(sv, std::basic_string_view(x));
+#endif
+}
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/starmath/inc/mathml/mathmlattr.hxx 
b/starmath/inc/mathml/mathmlattr.hxx
index f999f28d680a..16161fb4b8fb 100644
--- a/starmath/inc/mathml/mathmlattr.hxx
+++ b/starmath/inc/mathml/mathmlattr.hxx
@@ -9,6 +9,10 @@
 
 #pragma once
 
+#include 
+
+#include 
+
 #include 
 #include 
 #include 
@@ -44,7 +48,7 @@ struct MathMLAttributeLengthValue
 }
 };
 
-sal_Int32 ParseMathMLAttributeLengthValue(const OUString& rStr, 
MathMLAttributeLengthValue& rV);
+bool ParseMathMLAttributeLengthValue(std::u16string_view rStr, 
MathMLAttributeLengthValue& rV);
 
 // MathML 3: 3.2.2 Mathematics style attributes common to token elements
 // 
diff --git a/starmath/source/mathml/mathmlattr.cxx 
b/starmath/source/mathml/mathmlattr.cxx
index 7da7f947a8c6..ce28ec7836e9 100644
--- a/starmath/source/mathml/mathmlattr.cxx
+++ b/starmath/source/mathml/mathmlattr.cxx
@@ -10,14 +10,18 @@
 #include 
 
 #include 
+#include 
+#include 
 
+#include 
+#include 
 #include 
 
-static sal_Int32 ParseMathMLUnsignedNumber(const OUString& rStr, Fraction& rUN)
+static std::size_t ParseMathMLUnsignedNumber(std::u16string_view rStr, 
Fraction& rUN)
 {
-auto nLen = rStr.getLength();
-sal_Int32 nDecimalPoint = -1;
-sal_Int32 nIdx;
+auto nLen = rStr.length();
+std::size_t nDecimalPoint = std::u16string_view::npos;
+std::size_t nIdx;
 sal_Int64 nom = 0;
 sal_Int64 den = 1;
 bool validNomDen = true;
@@ -26,8 +30,8 @@ static sal_Int32 ParseMathMLUnsignedNumber(const OUString& 
rStr, Fraction& rUN)
 auto cD = rStr[nIdx];
 

[Libreoffice-commits] core.git: include/o3tl sw/source

2021-08-31 Thread Noel Grandin (via logerrit)
 include/o3tl/hash_combine.hxx   |   22 ++
 sw/source/core/inc/fntcache.hxx |   35 ++--
 sw/source/core/txtnode/fntcache.cxx |   77 +++-
 3 files changed, 77 insertions(+), 57 deletions(-)

New commits:
commit bb5425ed3d8cc04e4242059a17912752d6b48c53
Author: Noel Grandin 
AuthorDate: Sat Aug 28 18:53:07 2021 +0200
Commit: Noel Grandin 
CommitDate: Tue Aug 31 14:26:46 2021 +0200

tdf#135683 speed up writer layout cache access

can be hot, so use a std::unordered_map

Change-Id: I70e34e80cad67536414c71facbe0222dd88c65a7
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121208
Tested-by: Jenkins
Reviewed-by: Noel Grandin 

diff --git a/include/o3tl/hash_combine.hxx b/include/o3tl/hash_combine.hxx
index 139ee981699c..f56beda62672 100644
--- a/include/o3tl/hash_combine.hxx
+++ b/include/o3tl/hash_combine.hxx
@@ -11,6 +11,17 @@
 
 namespace o3tl
 {
+template 
+inline std::enable_if_t<(sizeof(N) == 4)> hash_combine(N& nSeed, T const* 
pValue, size_t nCount)
+{
+static_assert(sizeof(nSeed) == 4);
+for (size_t i = 0; i < nCount; ++i)
+{
+nSeed ^= std::hash{}(*pValue) + 0x9E3779B9u + (nSeed << 6) + (nSeed 
>> 2);
+++pValue;
+}
+}
+
 template 
 inline std::enable_if_t<(sizeof(N) == 4)> hash_combine(N& nSeed, T const& 
nValue)
 {
@@ -18,6 +29,17 @@ inline std::enable_if_t<(sizeof(N) == 4)> hash_combine(N& 
nSeed, T const& nValue
 nSeed ^= std::hash{}(nValue) + 0x9E3779B9u + (nSeed << 6) + (nSeed >> 
2);
 }
 
+template 
+inline std::enable_if_t<(sizeof(N) == 8)> hash_combine(N& nSeed, T const* 
pValue, size_t nCount)
+{
+static_assert(sizeof(nSeed) == 8);
+for (size_t i = 0; i < nCount; ++i)
+{
+nSeed ^= std::hash{}(*pValue) + 0x9E3779B97F4A7C15llu + (nSeed << 
12) + (nSeed >> 4);
+++pValue;
+}
+}
+
 template 
 inline std::enable_if_t<(sizeof(N) == 8)> hash_combine(N& nSeed, T const& 
nValue)
 {
diff --git a/sw/source/core/inc/fntcache.hxx b/sw/source/core/inc/fntcache.hxx
index ab5c6a9e473b..0bdc4757d9b3 100644
--- a/sw/source/core/inc/fntcache.hxx
+++ b/sw/source/core/inc/fntcache.hxx
@@ -23,7 +23,7 @@
 #include 
 
 #include 
-#include 
+#include 
 
 #include 
 #include 
@@ -60,9 +60,34 @@ void SwClearFntCacheTextGlyphs();
 extern SwFntCache *pFntCache;
 extern SwFntObj *pLastFont;
 
-struct SwTextGlyphsKey;
-bool operator<(const SwTextGlyphsKey& l, const SwTextGlyphsKey& r);
-struct SwTextGlyphsData;
+/**
+ * Defines a substring on a given output device, to be used as an 
std::unordered_map<>
+ * key.
+ */
+struct SwTextGlyphsKey
+{
+VclPtr m_pOutputDevice;
+OUString m_aText;
+sal_Int32 m_nIndex;
+sal_Int32 m_nLength;
+size_t mnHashCode;
+
+SwTextGlyphsKey(VclPtr const& pOutputDevice, const OUString 
& sText, sal_Int32 nIndex, sal_Int32 nLength);
+bool operator==(SwTextGlyphsKey const & rhs) const;
+};
+struct SwTextGlyphsKeyHash
+{
+size_t operator()(SwTextGlyphsKey const & rKey) const { return 
rKey.mnHashCode; }
+};
+/**
+ * Glyphs and text width for the given SwTextGlyphsKey.
+ */
+struct SwTextGlyphsData
+{
+SalLayoutGlyphs m_aTextGlyphs;
+tools::Long m_nTextWidth = -1; // -1 = not computed yet
+};
+typedef std::unordered_map SwTextGlyphsMap;
 
 class SwFntObj final : public SwCacheObj
 {
@@ -86,7 +111,7 @@ class SwFntObj final : public SwCacheObj
 bool m_bPaintBlank : 1;
 
 /// Cache of already calculated layout glyphs and text widths.
-std::map m_aTextGlyphs;
+SwTextGlyphsMap m_aTextGlyphs;
 
 static tools::Long s_nPixWidth;
 static MapMode *s_pPixMap;
diff --git a/sw/source/core/txtnode/fntcache.cxx 
b/sw/source/core/txtnode/fntcache.cxx
index 9490fe51add0..17be5c9f0eef 100644
--- a/sw/source/core/txtnode/fntcache.cxx
+++ b/sw/source/core/txtnode/fntcache.cxx
@@ -57,6 +57,7 @@
 #include 
 #include 
 #include 
+#include 
 
 using namespace ::com::sun::star;
 
@@ -73,26 +74,31 @@ MapMode* SwFntObj::s_pPixMap = nullptr;
 static vcl::DeleteOnDeinit< VclPtr > s_pFntObjPixOut {};
 
 /**
- * Defines a substring on a given output device, to be used as an std::map<>
+ * Defines a substring on a given output device, to be used as an 
std::unordered_map<>
  * key.
  */
-struct SwTextGlyphsKey
+SwTextGlyphsKey::SwTextGlyphsKey(VclPtr const& pOutputDevice, 
const OUString & sText, sal_Int32 nIndex, sal_Int32 nLength)
+: m_pOutputDevice(pOutputDevice), m_aText(sText), m_nIndex(nIndex), 
m_nLength(nLength)
 {
-VclPtr m_pOutputDevice;
-OUString m_aText;
-sal_Int32 m_nIndex;
-sal_Int32 m_nLength;
-
-};
-
-/**
- * Glyphs and text width for the given SwTextGlyphsKey.
- */
-struct SwTextGlyphsData
+mnHashCode = 0;
+o3tl::hash_combine(mnHashCode, pOutputDevice.get());
+o3tl::hash_combine(mnHashCode, m_nIndex);
+o3tl::hash_combine(mnHashCode, m_nLength);
+if(m_nLength >= 0 && m_nIndex >= 0 && m_nIndex + m_nLength <= 
m_aText.getLength())
+

[Libreoffice-commits] core.git: include/o3tl

2021-08-25 Thread Mike Kaganski (via logerrit)
 include/o3tl/float_int_conversion.hxx |1 +
 1 file changed, 1 insertion(+)

New commits:
commit c3a7edad85ec22fa4dac372da9e0b36d02efbfc4
Author: Mike Kaganski 
AuthorDate: Wed Aug 25 18:30:25 2021 +0200
Commit: Mike Kaganski 
CommitDate: Thu Aug 26 06:37:21 2021 +0200

Missing include

Change-Id: Idc533f1849c8be44ed04d3ed823c7f69c12c2d79
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120988
Tested-by: Jenkins
Reviewed-by: Mike Kaganski 

diff --git a/include/o3tl/float_int_conversion.hxx 
b/include/o3tl/float_int_conversion.hxx
index 36bce97dd742..403bed6221c3 100644
--- a/include/o3tl/float_int_conversion.hxx
+++ b/include/o3tl/float_int_conversion.hxx
@@ -13,6 +13,7 @@
 #include 
 
 #include 
+#include 
 #include 
 
 namespace o3tl


[Libreoffice-commits] core.git: include/o3tl include/oox

2021-08-24 Thread Mike Kaganski (via logerrit)
 include/o3tl/unit_conversion.hxx |   20 
 include/oox/drawingml/drawingmltypes.hxx |4 +---
 2 files changed, 21 insertions(+), 3 deletions(-)

New commits:
commit ae04cfdbad1f4c09b06cd2cee9d89e9909181acc
Author: Mike Kaganski 
AuthorDate: Mon Aug 23 16:28:10 2021 +0200
Commit: Mike Kaganski 
CommitDate: Tue Aug 24 10:37:21 2021 +0200

Introduce convertNarrowing to return smaller integer types

It will use compile-type constants to clamp input value, instead of
clamping more expensive pre-sanitized output value.

Change-Id: If78f8b1b4c99bd2f16b1d8a71872e89a08d0
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120874
Tested-by: Jenkins
Reviewed-by: Mike Kaganski 

diff --git a/include/o3tl/unit_conversion.hxx b/include/o3tl/unit_conversion.hxx
index cf293662e7b2..7bee0ed397e5 100644
--- a/include/o3tl/unit_conversion.hxx
+++ b/include/o3tl/unit_conversion.hxx
@@ -221,6 +221,26 @@ template  constexpr auto 
convertSaturate(N n, U from, U
 return detail::MulDivSaturate(n, detail::md(from, to), detail::md(to, 
from));
 }
 
+// Conversion with saturation (only for integral types), optimized for return 
types smaller than
+// sal_Int64. In this case, it's easier to clamp input values to known bounds, 
than to do some
+// preprocessing to handle too large input values, just to clamp the result 
anyway. Use it like:
+//
+// sal_Int32 n = convertNarrowing(m);
+template  && std::is_integral_v && sizeof(Out) 
< sizeof(sal_Int64),
+  int> = 0>
+constexpr Out convertNarrowing(N n)
+{
+constexpr sal_Int64 nMin = 
convertSaturate(std::numeric_limits::min(), to, from);
+constexpr sal_Int64 nMax = 
convertSaturate(std::numeric_limits::max(), to, from);
+if (static_cast(n) > nMax)
+return std::numeric_limits::max();
+if (static_cast(n) < nMin)
+return std::numeric_limits::min();
+return convert(n, from, to);
+}
+
 // Return a pair { multiplier, divisor } for a given conversion
 template  constexpr std::pair 
getConversionMulDiv(U from, U to)
 {
diff --git a/include/oox/drawingml/drawingmltypes.hxx 
b/include/oox/drawingml/drawingmltypes.hxx
index 05d218fa882e..4350b8d033a7 100644
--- a/include/oox/drawingml/drawingmltypes.hxx
+++ b/include/oox/drawingml/drawingmltypes.hxx
@@ -180,9 +180,7 @@ inline sal_Int64 convertHmmToEmu( sal_Int32 nValue )
 /** Converts the passed 64-bit integer value from EMUs to 1/100 mm. */
 inline sal_Int32 convertEmuToHmm( sal_Int64 nValue )
 {
-return getLimitedValue(
-o3tl::convertSaturate(nValue, o3tl::Length::emu, o3tl::Length::mm100), 
SAL_MIN_INT32,
-SAL_MAX_INT32);
+return o3tl::convertNarrowing(nValue);
 }
 
 /** Converts the passed 64-bit integer value from EMUs to Points. */


[Libreoffice-commits] core.git: include/o3tl o3tl/qa sw/inc sw/qa sw/source

2021-08-09 Thread Tomaž Vajngerl (via logerrit)
 include/o3tl/unit_conversion.hxx|6 ++
 o3tl/qa/test-unit_conversion.cxx|7 +++
 sw/inc/swtypes.hxx  |   19 ++-
 sw/qa/extras/tiledrendering/tiledrendering.cxx  |3 ++-
 sw/source/core/doc/DocumentStylePoolManager.cxx |6 +++---
 sw/source/core/doc/lineinfo.cxx |2 +-
 sw/source/core/edit/edattr.cxx  |9 +++--
 sw/source/core/frmedt/feshview.cxx  |   10 ++
 sw/source/core/layout/calcmove.cxx  |4 +++-
 sw/source/core/unocore/unoframe.cxx |5 +++--
 sw/source/core/unocore/unostyle.cxx |3 ++-
 sw/source/filter/html/htmlnum.hxx   |4 ++--
 sw/source/filter/html/htmlplug.cxx  |9 +
 sw/source/filter/html/htmltab.cxx   |4 +++-
 sw/source/filter/html/svxcss1.hxx   |3 ++-
 sw/source/filter/html/swhtml.hxx|8 
 sw/source/filter/html/wrthtml.hxx   |2 +-
 sw/source/ui/chrdlg/pardlg.cxx  |3 ++-
 sw/source/ui/dbui/mmlayoutpage.cxx  |   10 +-
 sw/source/ui/fmtui/tmpdlg.cxx   |3 ++-
 sw/source/ui/misc/pggrid.cxx|4 +++-
 sw/source/uibase/dochdl/swdtflvr.cxx|5 -
 sw/source/uibase/inc/frmmgr.hxx |4 ++--
 sw/source/uibase/ribbar/conform.cxx |   11 +++
 sw/source/uibase/ribbar/drawbase.cxx|   10 ++
 sw/source/uibase/shells/textsh.cxx  |8 +---
 sw/source/uibase/wrtsh/wrtsh1.cxx   |3 ++-
 27 files changed, 105 insertions(+), 60 deletions(-)

New commits:
commit 9da7b1592e010928c26c43ee93b91cdd66403985
Author: Tomaž Vajngerl 
AuthorDate: Fri Jul 23 08:44:14 2021 +0900
Commit: Tomaž Vajngerl 
CommitDate: Tue Aug 10 03:02:52 2021 +0200

sw: remove all uses of MM50 with (added) o3tl::toTwip

MM50 constant is the number of twips for 5mm. This is (ab)used as
a "shortcut" to set or compare various variables through the code
and also to set a multiplied value (like 1cm, 2cm, 4cm) or divided
value (2.5mm, 1.25mm). The problem with this is that converting the
5mm to twip doesn't round up exactly and multiplied and divided
values increase the error even more.

Instead of basing it from MM50 constant, it is just better to use
our o3tl::convert (or the added variant o3tl::toTwip), which can
actually calculate the conversion at compile time, so there is no
added complexity at runtime and we get a more readable code with
more exact result.

i.e.
o3tl::toTwip(4, o3tl::Length::cm)
instead of the more cryptic
MM50 * 8

In addition also sanitize and comment the values of the constants
in sw/inc/swtypes.hxx.

Change-Id: I85c306c36207d47ac3dc207094b68d0fb1ca5b70
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119397
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl 

diff --git a/include/o3tl/unit_conversion.hxx b/include/o3tl/unit_conversion.hxx
index 4c76375737a2..cf293662e7b2 100644
--- a/include/o3tl/unit_conversion.hxx
+++ b/include/o3tl/unit_conversion.hxx
@@ -199,6 +199,12 @@ template  constexpr auto convert(N 
n, U from, U to)
 return convert(n, detail::md(from, to), detail::md(to, from));
 }
 
+// Convert to twips - for convenience as we do this a lot
+template  constexpr auto toTwips(N number, Length from)
+{
+return convert(number, from, Length::twip);
+}
+
 // Returns nDefault if intermediate multiplication overflows sal_Int64 (only 
for integral types).
 // On return, bOverflow indicates if overflow happened. nDefault is returned 
when overflow occurs.
 template 
diff --git a/o3tl/qa/test-unit_conversion.cxx b/o3tl/qa/test-unit_conversion.cxx
index 983c0845a4cd..80b01ea2bf2b 100644
--- a/o3tl/qa/test-unit_conversion.cxx
+++ b/o3tl/qa/test-unit_conversion.cxx
@@ -869,4 +869,11 @@ static_assert(o3tl::convert(100, o3tl::Length::line, 
o3tl::Length::line) == 100)
 static_assert(o3tl::convert(49, o3tl::Length::mm100, o3tl::Length::mm) == 0);
 static_assert(o3tl::convert(50, o3tl::Length::mm100, o3tl::Length::mm) == 1);
 
+// Conversions used in the code - to make sure they produce the expected and 
unchanged result
+
+static_assert(o3tl::toTwips(25, o3tl::Length::in100) == 1440 / 4);
+static_assert(o3tl::toTwips(15, o3tl::Length::in100) == 216);
+// the following twip value used to the constant for 20mm
+static_assert(o3tl::toTwips(20, o3tl::Length::mm) == 1134);
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/sw/inc/swtypes.hxx b/sw/inc/swtypes.hxx
index 81ad502b82be..ff79edb47d02 100644
--- a/sw/inc/swtypes.hxx
+++ b/sw/inc/swtypes.hxx
@@ -25,6 +25,7 @@
 #include 
 #include "swdllapi.h"
 #include 
+#include 
 #include 
 #include 
 #include 
@@ 

[Libreoffice-commits] core.git: include/o3tl

2021-08-04 Thread Noel Grandin (via logerrit)
 include/o3tl/cow_wrapper.hxx |5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

New commits:
commit 2f343f09b4adaed1fe7286dfc8ba73bdb13eeabf
Author: Noel Grandin 
AuthorDate: Wed Aug 4 15:58:34 2021 +0200
Commit: Noel Grandin 
CommitDate: Wed Aug 4 18:15:00 2021 +0200

tsan:datarace in o3tl::ThreadSafeRefCountingPolicy

Because we a non-atomic read of the reference count.

Which we shouldn't be doing anyway, or the ref-counting is broken.

WARNING: ThreadSanitizer: data race (pid=121172)
  Read of size 4 at 0x7b100027ba38 by thread T5:
/media/disk2/libo-san/include/o3tl/cow_wrapper.hxx:54:17
(libvcllo.so+0x7ee40d)
o3tl::ThreadSafeRefCountingPolicy>::release()
/media/disk2/libo-san/include/o3tl/cow_wrapper.hxx:208:29
(libvcllo.so+0x7ee40d)
o3tl::ThreadSafeRefCountingPolicy>::~cow_wrapper()
/media/disk2/libo-san/include/o3tl/cow_wrapper.hxx:260:13
(libvcllo.so+0x7ee40d)
/media/disk2/libo-san/vcl/source/gdi/mapmod.cxx:97:19
(libvcllo.so+0x7ee40d)
/media/disk2/libo-san/vcl/source/bitmap/bitmap.cxx:166:1
(libvcllo.so+0x92b175)
/media/disk2/libo-san/vcl/source/bitmap/alpha.cxx:49:23
(libvcllo.so+0x946475)
GraphicFilterImportFlags, vcl::ScopedBitmapAccess*,
vcl::ScopedBitmapAccess*)
/media/disk2/libo-san/vcl/source/filter/png/PngImageReader.cxx:383:1
(libvcllo.so+0xb67860)
vcl::ScopedBitmapAccess*,
vcl::ScopedBitmapAccess*)
/media/disk2/libo-san/vcl/source/filter/png/PngImageReader.cxx:479:9
(libvcllo.so+0xb69139)
namespace)::GraphicImportContext&)
/media/disk2/libo-san/vcl/source/filter/graphicfilter.cxx:586:14
(libvcllo.so+0xac3a2f)
/media/disk2/libo-san/vcl/source/filter/graphicfilter.cxx:574:5
(libvcllo.so+0xac3a2f)
/media/disk2/libo-san/comphelper/source/misc/threadpool.cxx:314:9
(libcomphelper.so+0x1480ff)
/media/disk2/libo-san/comphelper/source/misc/threadpool.cxx:83:24
(libcomphelper.so+0x1480ff)
/media/disk2/libo-san/salhelper/source/thread.cxx:40:9
(libuno_salhelpergcc3.so.3+0x5350)
/media/disk2/libo-san/salhelper/source/thread.cxx
(libuno_salhelpergcc3.so.3+0x53b9)
(libuno_salhelpergcc3.so.3+0x565e)
/media/disk2/libo-san/sal/osl/unx/thread.cxx:264:9
(libuno_sal.so.3+0x68325)

Previous atomic write of size 4 at 0x7b100027ba38 by main thread
(mutexes: write M7453640868405680):
/media/disk2/libo-san/include/o3tl/cow_wrapper.hxx:57:24
(libvcllo.so+0x7eebc9)
o3tl::ThreadSafeRefCountingPolicy>::release()
/media/disk2/libo-san/include/o3tl/cow_wrapper.hxx:208:29
(libvcllo.so+0x7eebc9)

o3tl::ThreadSafeRefCountingPolicy>::operator=(o3tl::cow_wrapper const&)
/media/disk2/libo-san/include/o3tl/cow_wrapper.hxx:269:13
(libvcllo.so+0x7eebc9)
/media/disk2/libo-san/vcl/source/gdi/mapmod.cxx:124:45
(libvcllo.so+0x7eebc9)

Change-Id: I6334b748b91bf414168c05d90fc5bd6d7dfe3dda
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120005
Tested-by: Jenkins
Reviewed-by: Noel Grandin 

diff --git a/include/o3tl/cow_wrapper.hxx b/include/o3tl/cow_wrapper.hxx
index 8cc3651030fd..c05d28699259 100644
--- a/include/o3tl/cow_wrapper.hxx
+++ b/include/o3tl/cow_wrapper.hxx
@@ -51,10 +51,7 @@ namespace o3tl
 static void incrementCount( ref_count_t& rCount ) { 
osl_atomic_increment(); }
 static bool decrementCount( ref_count_t& rCount )
 {
-if( rCount == 1 ) // caller is already the only/last reference
-return false;
-else
-return osl_atomic_decrement() != 0;
+return osl_atomic_decrement() != 0;
 }
 };
 


[Libreoffice-commits] core.git: include/o3tl

2021-07-28 Thread Mike Kaganski (via logerrit)
 include/o3tl/safeint.hxx |   30 ++
 1 file changed, 2 insertions(+), 28 deletions(-)

New commits:
commit 44a4b028d094dda4dc4886a4670371175da8024f
Author: Mike Kaganski 
AuthorDate: Wed Jul 28 03:30:35 2021 +0200
Commit: Stephan Bergmann 
CommitDate: Wed Jul 28 08:52:03 2021 +0200

Consolidate saturating_(add,sub) for signed and unsigned

Compiler would optimize away the branch that is unreachable
for current operand type anyway.

Change-Id: Iac84057c1716990d107529d52dba1dd7603c5a32
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119448
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/o3tl/safeint.hxx b/include/o3tl/safeint.hxx
index 801b3dc6fdd5..85c61f8c33d3 100644
--- a/include/o3tl/safeint.hxx
+++ b/include/o3tl/safeint.hxx
@@ -27,9 +27,7 @@
 namespace o3tl
 {
 
-template inline
-typename std::enable_if::value, T>::type saturating_add(
-T a, T b)
+template  inline T saturating_add(T a, T b)
 {
 if (b >= 0) {
 if (a <= std::numeric_limits::max() - b) {
@@ -46,20 +44,7 @@ typename std::enable_if::value, T>::type 
saturating_add(
 }
 }
 
-template inline
-typename std::enable_if::value, T>::type saturating_add(
-T a, T b)
-{
-if (a <= std::numeric_limits::max() - b) {
-return a + b;
-} else {
-return std::numeric_limits::max();
-}
-}
-
-template inline
-typename std::enable_if::value, T>::type saturating_sub(
-T a, T b)
+template  inline T saturating_sub(T a, T b)
 {
 if (b >= 0) {
 if (a >= std::numeric_limits::min() + b) {
@@ -76,17 +61,6 @@ typename std::enable_if::value, T>::type 
saturating_sub(
 }
 }
 
-template inline
-typename std::enable_if::value, T>::type saturating_sub(
-T a, T b)
-{
-if (a >= std::numeric_limits::min() + b) {
-return a - b;
-} else {
-return std::numeric_limits::min();
-}
-}
-
 template inline
 typename std::enable_if::value, T>::type 
saturating_toggle_sign(
 T a)
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/o3tl o3tl/qa

2021-06-09 Thread Luboš Luňák (via logerrit)
 include/o3tl/lru_map.hxx |9 -
 o3tl/qa/test-lru_map.cxx |   14 ++
 2 files changed, 22 insertions(+), 1 deletion(-)

New commits:
commit 62b58e88d897f51a7c4e12b41d14121ab8d3396f
Author: Luboš Luňák 
AuthorDate: Wed Jun 9 17:10:42 2021 +0200
Commit: Luboš Luňák 
CommitDate: Wed Jun 9 21:20:09 2021 +0200

allow altering the max size of o3tl::lru_cache

Change-Id: Id119b70275e1c88a8c57f89d915241427be9dbf5
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116927
Tested-by: Jenkins
Reviewed-by: Luboš Luňák 

diff --git a/include/o3tl/lru_map.hxx b/include/o3tl/lru_map.hxx
index dc8a102977dd..41c215255c7a 100644
--- a/include/o3tl/lru_map.hxx
+++ b/include/o3tl/lru_map.hxx
@@ -50,7 +50,7 @@ private:
 
 list_t mLruList;
 map_t mLruMap;
-const size_t mMaxSize;
+size_t mMaxSize;
 
 void checkLRU()
 {
@@ -80,6 +80,13 @@ public:
 list_t().swap(mLruList);
 }
 
+void setMaxSize(size_t nMaxSize)
+{
+mMaxSize = nMaxSize ? nMaxSize : std::min(mLruMap.max_size(), 
mLruList.max_size());
+while (mLruMap.size() > mMaxSize)
+checkLRU();
+}
+
 void insert(key_value_pair_t& rPair)
 {
 map_iterator_t i = mLruMap.find(rPair.first);
diff --git a/o3tl/qa/test-lru_map.cxx b/o3tl/qa/test-lru_map.cxx
index ef46f44d17b9..aac8a3e25283 100644
--- a/o3tl/qa/test-lru_map.cxx
+++ b/o3tl/qa/test-lru_map.cxx
@@ -29,6 +29,7 @@ public:
 void testCustomHash();
 void testRemoveIf();
 void testNoAutoCleanup();
+void testChangeMaxSize();
 
 CPPUNIT_TEST_SUITE(lru_map_test);
 CPPUNIT_TEST(testBaseUsage);
@@ -38,6 +39,7 @@ public:
 CPPUNIT_TEST(testCustomHash);
 CPPUNIT_TEST(testRemoveIf);
 CPPUNIT_TEST(testNoAutoCleanup);
+CPPUNIT_TEST(testChangeMaxSize);
 CPPUNIT_TEST_SUITE_END();
 };
 
@@ -310,6 +312,18 @@ void lru_map_test::testNoAutoCleanup()
 }
 }
 
+void lru_map_test::testChangeMaxSize()
+{
+o3tl::lru_map lru(3);
+CPPUNIT_ASSERT_EQUAL(size_t(0), lru.size());
+lru.insert({ 0, 0 });
+lru.insert({ 1, 1 });
+lru.insert({ 2, 2 });
+CPPUNIT_ASSERT_EQUAL(size_t(3), lru.size());
+lru.setMaxSize(1);
+CPPUNIT_ASSERT_EQUAL(size_t(1), lru.size());
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(lru_map_test);
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/o3tl include/rtl sal/rtl sal/util sdext/source

2021-05-18 Thread Stephan Bergmann (via logerrit)
 include/o3tl/string_view.hxx   |   24 ++
 include/rtl/string.h   |   39 -
 include/rtl/string.hxx |9 ---
 sal/rtl/string.cxx |5 --
 sal/rtl/strtmpl.hxx|   66 -
 sal/util/sal.map   |5 --
 sdext/source/pdfimport/wrapper/wrapper.cxx |   38 
 7 files changed, 44 insertions(+), 142 deletions(-)

New commits:
commit eca89ece45ede76605a6102c94b3b67e1f8ff5aa
Author: Stephan Bergmann 
AuthorDate: Tue May 18 14:23:15 2021 +0200
Commit: Stephan Bergmann 
CommitDate: Tue May 18 16:10:41 2021 +0200

Replace rtl_string_getTokenView with o3tl::getToken

...to not needlessly extend the sal ABI.

At least for now, o3tl::getToken has a simpler interface than its
OString::getToken counterpart (driven mainly by how it is used for now): it 
does
not support a `token` argument, and its `position` argument must not be 
npos.
To meet the latter requirement, the check for "subpath" in 
LineParser::readPath
has been reworked slightly.

Change-Id: I4428fe2d9aa03ca83a436fc6493fbc34665a8033
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115742
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/o3tl/string_view.hxx b/include/o3tl/string_view.hxx
index d343befd0efe..5ebbb0b9f044 100644
--- a/include/o3tl/string_view.hxx
+++ b/include/o3tl/string_view.hxx
@@ -11,6 +11,8 @@
 
 #include 
 
+#include 
+#include 
 #include 
 
 #include 
@@ -22,6 +24,28 @@ inline bool equalsIgnoreAsciiCase(std::u16string_view s1, 
std::u16string_view s2
 {
 return rtl_ustr_compareIgnoreAsciiCase_WithLength(s1.data(), s1.size(), 
s2.data(), s2.size());
 };
+
+// Similar to OString::getToken, returning the first token of a 
std::string_view, starting at a
+// given position (and if needed, it can be turned into a template to also 
cover std::u16string_view
+// etc., or extended to return the n'th token instead of just the first, or 
support an initial
+// position of npos):
+inline std::string_view getToken(std::string_view sv, char delimiter, 
std::size_t& position)
+{
+assert(position <= sv.size());
+auto const n = sv.find(delimiter, position);
+std::string_view t;
+if (n == std::string_view::npos)
+{
+t = sv.substr(position);
+position = std::string_view::npos;
+}
+else
+{
+t = sv.substr(position, n - position);
+position = n + 1;
+}
+return t;
+}
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/include/rtl/string.h b/include/rtl/string.h
index c86468c7f302..d29caf93a718 100644
--- a/include/rtl/string.h
+++ b/include/rtl/string.h
@@ -1309,45 +1309,6 @@ SAL_DLLPUBLIC void SAL_CALL rtl_string_newTrim(
 SAL_DLLPUBLIC sal_Int32 SAL_CALL rtl_string_getToken(
 rtl_String ** newStr , rtl_String * str, sal_Int32 token, char cTok, 
sal_Int32 idx ) SAL_THROW_EXTERN_C();
 
-/** @cond INTERNAL */
-/** Create a new string by extracting a single token from another string.
-
-Starting at index, the next token is searched for.  If there is no
-such token, the result is an empty string.  Otherwise, all characters from
-the start of that token and up to, but not including the next occurrence
-of cTok make up the resulting token.  The return value is the position of
-the next token, or -1 if no more tokens follow.
-
-This function does not handle out-of-memory conditions.
-
-@param ppViewStr
-pointer to the start of the token.
-
-@param pViewLength
-length of the token.
-
-@param str
-a valid string.
-
-@param token
-the number of the token to return, starting at index.
-
-@param cTok
-the character that separates the tokens.
-
-@param idx
-the position at which searching for the token starts.  Must not be greater
-than the length of str.
-
-@return
-the index of the next token, or -1 if no more tokens follow.
-
-@since LibreOffice 7.2
- */
-SAL_DLLPUBLIC sal_Int32 SAL_CALL rtl_string_getTokenView(
-const char ** ppViewStr , sal_Int32* pViewLength, rtl_String * str, 
sal_Int32 token, char cTok, sal_Int32 idx ) SAL_THROW_EXTERN_C();
-/** @endcond */
-
 /* === */
 
 /** Supply an ASCII string literal together with its length.
diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx
index 3fc461de0c2c..f80dd7410da7 100644
--- a/include/rtl/string.hxx
+++ b/include/rtl/string.hxx
@@ -1765,15 +1765,6 @@ public:
 index = rtl_string_getToken( , pData, token, cTok, index );
 return OString( pNew, SAL_NO_ACQUIRE );
 }
-#ifdef LIBO_INTERNAL_ONLY
-std::string_view getTokenView( sal_Int32 token, char cTok, sal_Int32& 
index ) const
-{
-const char* pViewData 

[Libreoffice-commits] core.git: include/o3tl o3tl/qa

2021-05-11 Thread Tomaž Vajngerl (via logerrit)
 include/o3tl/hash_combine.hxx |   29 +
 o3tl/qa/test-lru_map.cxx  |6 +++---
 2 files changed, 32 insertions(+), 3 deletions(-)

New commits:
commit e6c0c282be59a5198932604d6c40de837b7cb548
Author: Tomaž Vajngerl 
AuthorDate: Wed May 27 12:49:05 2020 +0200
Commit: Tomaž Vajngerl 
CommitDate: Tue May 11 12:23:48 2021 +0200

add o3tl version of hash_combine to not depend on boost for this

Change-Id: I081f8d116ef811baa8aa5de35a6cb51fa4de7d56
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114983
Tested-by: Tomaž Vajngerl 
Reviewed-by: Tomaž Vajngerl 

diff --git a/include/o3tl/hash_combine.hxx b/include/o3tl/hash_combine.hxx
new file mode 100644
index ..17419b3e2c0f
--- /dev/null
+++ b/include/o3tl/hash_combine.hxx
@@ -0,0 +1,29 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#pragma once
+
+namespace o3tl
+{
+template  = 
false>
+inline void hash_combine(N& nSeed, T const& nValue)
+{
+static_assert(sizeof(nSeed) == 4);
+nSeed ^= std::hash{}(nValue) + 0x9E3779B9u + (nSeed << 6) + (nSeed >> 
2);
+}
+
+template  = 
false>
+inline void hash_combine(N& nSeed, T const& nValue)
+{
+static_assert(sizeof(nSeed) == 8);
+nSeed ^= std::hash{}(nValue) + 0x9E3779B97F4A7C15llu + (nSeed << 12) + 
(nSeed >> 4);
+}
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/o3tl/qa/test-lru_map.cxx b/o3tl/qa/test-lru_map.cxx
index ba9ee71835ce..ef46f44d17b9 100644
--- a/o3tl/qa/test-lru_map.cxx
+++ b/o3tl/qa/test-lru_map.cxx
@@ -15,7 +15,7 @@
 
 #include 
 
-#include 
+#include 
 
 using namespace ::o3tl;
 
@@ -202,8 +202,8 @@ struct TestClassKeyHashFunction
 std::size_t operator()(TestClassKey const& aKey) const
 {
 std::size_t seed = 0;
-boost::hash_combine(seed, aKey.mA);
-boost::hash_combine(seed, aKey.mB);
+o3tl::hash_combine(seed, aKey.mA);
+o3tl::hash_combine(seed, aKey.mB);
 return seed;
 }
 };
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/o3tl

2021-03-30 Thread Mike Kaganski (via logerrit)
 include/o3tl/unit_conversion.hxx |   20 
 1 file changed, 8 insertions(+), 12 deletions(-)

New commits:
commit 852c4f8cded79435bd69675e9e9a10034b385219
Author: Mike Kaganski 
AuthorDate: Tue Mar 30 09:02:12 2021 +0200
Commit: Mike Kaganski 
CommitDate: Tue Mar 30 10:11:45 2021 +0200

Simplify prepareMDArray

Change-Id: I1b8c0dead67b48c25ddcc02e83c3305cf93ebd5b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113288
Tested-by: Jenkins
Reviewed-by: Mike Kaganski 

diff --git a/include/o3tl/unit_conversion.hxx b/include/o3tl/unit_conversion.hxx
index 434f2e50c1c8..4c76375737a2 100644
--- a/include/o3tl/unit_conversion.hxx
+++ b/include/o3tl/unit_conversion.hxx
@@ -128,19 +128,15 @@ template  constexpr auto prepareMDArray(const 
m_and_d ()[N])
 std::array, N> a{};
 for (int i = 0; i < N; ++i)
 {
-for (int j = 0; j <= i; ++j)
+a[i][i] = 1;
+for (int j = 0; j < i; ++j)
 {
-if (i == j)
-a[i][j] = 1;
-else
-{
-assert(mdBase[i].m < SAL_MAX_INT64 / mdBase[j].d);
-assert(mdBase[i].d < SAL_MAX_INT64 / mdBase[j].m);
-const sal_Int64 m = mdBase[i].m * mdBase[j].d, d = mdBase[i].d 
* mdBase[j].m;
-const sal_Int64 g = std::gcd(m, d);
-a[i][j] = m / g;
-a[j][i] = d / g;
-}
+assert(mdBase[i].m < SAL_MAX_INT64 / mdBase[j].d);
+assert(mdBase[i].d < SAL_MAX_INT64 / mdBase[j].m);
+const sal_Int64 m = mdBase[i].m * mdBase[j].d, d = mdBase[i].d * 
mdBase[j].m;
+const sal_Int64 g = std::gcd(m, d);
+a[i][j] = m / g;
+a[j][i] = d / g;
 }
 }
 return a;
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/o3tl vcl/source

2021-03-27 Thread Caolán McNamara (via logerrit)
 include/o3tl/safeint.hxx|   10 ++
 vcl/source/font/fontcharmap.cxx |2 --
 2 files changed, 2 insertions(+), 10 deletions(-)

New commits:
commit 780e1ffb991f3bfc4e8a73714b0e2a464feb3a86
Author: Caolán McNamara 
AuthorDate: Sat Mar 27 19:43:46 2021 +
Commit: Caolán McNamara 
CommitDate: Sat Mar 27 21:55:55 2021 +0100

cid#1473755 Untrusted loop bound

deem_sanizize isn't sufficiently complex to sanize its input apparently

Change-Id: Id1d73feefce9b587a8024021d8766267b105b4f1
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113234
Tested-by: Jenkins
Reviewed-by: Caolán McNamara 

diff --git a/include/o3tl/safeint.hxx b/include/o3tl/safeint.hxx
index ef0b6593ad76..801b3dc6fdd5 100644
--- a/include/o3tl/safeint.hxx
+++ b/include/o3tl/safeint.hxx
@@ -239,17 +239,11 @@ make_unsigned(T value)
 // tools like -fsanitize=implicit-conversion should still be able to detect 
truncation:
 template constexpr T1 narrowing(T2 value) { return 
value; }
 
-// inform coverity that the returned value is now deemed sanitized
-// coverity[ -taint_source ]
-template [[nodiscard]] constexpr T deem_sanitized(T a)
-{
-return a;
-}
-
 // std::min wrapped to inform coverity that the result is now deemed sanitized
+// coverity[ -taint_source ]
 template [[nodiscard]] inline T sanitizing_min(T a, T b)
 {
-return o3tl::deem_sanitized(std::min(a, b));
+return std::min(a, b);
 }
 
 }
diff --git a/vcl/source/font/fontcharmap.cxx b/vcl/source/font/fontcharmap.cxx
index ac4336137735..e68939d3885e 100644
--- a/vcl/source/font/fontcharmap.cxx
+++ b/vcl/source/font/fontcharmap.cxx
@@ -23,7 +23,6 @@
 
 #include 
 #include 
-#include 
 #include 
 
 CmapResult::CmapResult( bool bSymbolic,
@@ -113,7 +112,6 @@ bool ParseCMAP( const unsigned char* pCmap, int nLength, 
CmapResult& rResult )
 int nSubTables = GetUShort( pCmap + 2 );
 if( (nSubTables <= 0) || (nLength < (24 + 8*nSubTables)) )
 return false;
-nSubTables = o3tl::deem_sanitized(nSubTables);
 
 const unsigned char* pEndValidArea = pCmap + nLength;
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/o3tl

2021-03-27 Thread Caolán McNamara (via logerrit)
 include/o3tl/safeint.hxx |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

New commits:
commit 18a0a72a94cd386b9f784a6bb7925a47c45e6e0b
Author: Caolán McNamara 
AuthorDate: Fri Mar 26 20:04:21 2021 +
Commit: Caolán McNamara 
CommitDate: Sat Mar 27 20:10:26 2021 +0100

make deem_sanitized a constexpr

Change-Id: I30e9b42fa0a296faafbb51634dcbc1a56adb2d41
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113208
Tested-by: Jenkins
Reviewed-by: Caolán McNamara 

diff --git a/include/o3tl/safeint.hxx b/include/o3tl/safeint.hxx
index 522eb166912b..ef0b6593ad76 100644
--- a/include/o3tl/safeint.hxx
+++ b/include/o3tl/safeint.hxx
@@ -241,7 +241,7 @@ template constexpr T1 
narrowing(T2 value) { return val
 
 // inform coverity that the returned value is now deemed sanitized
 // coverity[ -taint_source ]
-template [[nodiscard]] inline T deem_sanitized(T a)
+template [[nodiscard]] constexpr T deem_sanitized(T a)
 {
 return a;
 }
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/o3tl

2021-03-26 Thread Caolán McNamara (via logerrit)
 include/o3tl/safeint.hxx |   12 +---
 1 file changed, 9 insertions(+), 3 deletions(-)

New commits:
commit 65b99967c4da8e57ebabc9bed98818750fc82038
Author: Caolán McNamara 
AuthorDate: Fri Mar 26 16:40:27 2021 +
Commit: Caolán McNamara 
CommitDate: Fri Mar 26 20:41:12 2021 +0100

split this to give a sanitizing return pass through

Change-Id: I81eba14e31fe12fc92403c15e5d46f0493022f50
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113169
Tested-by: Jenkins
Reviewed-by: Caolán McNamara 

diff --git a/include/o3tl/safeint.hxx b/include/o3tl/safeint.hxx
index c2610edacec6..522eb166912b 100644
--- a/include/o3tl/safeint.hxx
+++ b/include/o3tl/safeint.hxx
@@ -239,11 +239,17 @@ make_unsigned(T value)
 // tools like -fsanitize=implicit-conversion should still be able to detect 
truncation:
 template constexpr T1 narrowing(T2 value) { return 
value; }
 
-// std::min wrapped to inform coverity that the result is now deemed sanitized
+// inform coverity that the returned value is now deemed sanitized
 // coverity[ -taint_source ]
-template inline T sanitizing_min(T a, T b)
+template [[nodiscard]] inline T deem_sanitized(T a)
+{
+return a;
+}
+
+// std::min wrapped to inform coverity that the result is now deemed sanitized
+template [[nodiscard]] inline T sanitizing_min(T a, T b)
 {
-return std::min(a, b);
+return o3tl::deem_sanitized(std::min(a, b));
 }
 
 }
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/o3tl

2021-03-25 Thread Caolán McNamara (via logerrit)
 include/o3tl/safeint.hxx |   13 +++--
 1 file changed, 3 insertions(+), 10 deletions(-)

New commits:
commit f8965272055bf9e7f3a26ff9f729d88ee856b592
Author: Caolán McNamara 
AuthorDate: Thu Mar 25 16:33:16 2021 +
Commit: Caolán McNamara 
CommitDate: Thu Mar 25 20:39:19 2021 +0100

cid#1474353 experiment to silence Untrusted loop bound

Change-Id: I4436427109c92a28890a1bc7f669841c40ec2020
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113101
Tested-by: Jenkins
Reviewed-by: Caolán McNamara 

diff --git a/include/o3tl/safeint.hxx b/include/o3tl/safeint.hxx
index 71239d59c718..c2610edacec6 100644
--- a/include/o3tl/safeint.hxx
+++ b/include/o3tl/safeint.hxx
@@ -239,18 +239,11 @@ make_unsigned(T value)
 // tools like -fsanitize=implicit-conversion should still be able to detect 
truncation:
 template constexpr T1 narrowing(T2 value) { return 
value; }
 
-// std::min wrapped to inform coverity that the result is now sanitized
-#if defined(__COVERITY__)
-extern "C" void __coverity_tainted_data_sanitize__(void *);
-#endif
-
+// std::min wrapped to inform coverity that the result is now deemed sanitized
+// coverity[ -taint_source ]
 template inline T sanitizing_min(T a, T b)
 {
-T ret = std::min(a, b);
-#if defined(__COVERITY__)
-__coverity_tainted_data_sanitize__();
-#endif
-return ret;
+return std::min(a, b);
 }
 
 }
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/o3tl tools/source

2021-03-24 Thread Caolán McNamara (via logerrit)
 include/o3tl/safeint.hxx   |   18 +++---
 tools/source/stream/stream.cxx |2 +-
 2 files changed, 16 insertions(+), 4 deletions(-)

New commits:
commit 69a32bec9b7121bd56560896828e76059bb49012
Author: Caolán McNamara 
AuthorDate: Wed Mar 24 10:15:28 2021 +
Commit: Caolán McNamara 
CommitDate: Wed Mar 24 21:32:10 2021 +0100

cid#1474353 experiment to silence Untrusted loop bound

the value *is* surely sanity checked here despite coverity's
bleating that it has passed through std::min unchanged when
it is the min value

Change-Id: Ic4f2b718832f88528f842280b4c0e04c4b3a9444
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113031
Tested-by: Caolán McNamara 
Reviewed-by: Caolán McNamara 

diff --git a/include/o3tl/safeint.hxx b/include/o3tl/safeint.hxx
index 9df92ea1a9d1..71239d59c718 100644
--- a/include/o3tl/safeint.hxx
+++ b/include/o3tl/safeint.hxx
@@ -7,11 +7,11 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  */
 
-#ifndef INCLUDED_O3TL_SAFEINT_HXX
-#define INCLUDED_O3TL_SAFEINT_HXX
+#pragma once
 
 #include 
 
+#include 
 #include 
 #include 
 #include 
@@ -239,8 +239,20 @@ make_unsigned(T value)
 // tools like -fsanitize=implicit-conversion should still be able to detect 
truncation:
 template constexpr T1 narrowing(T2 value) { return 
value; }
 
-}
+// std::min wrapped to inform coverity that the result is now sanitized
+#if defined(__COVERITY__)
+extern "C" void __coverity_tainted_data_sanitize__(void *);
+#endif
 
+template inline T sanitizing_min(T a, T b)
+{
+T ret = std::min(a, b);
+#if defined(__COVERITY__)
+__coverity_tainted_data_sanitize__();
 #endif
+return ret;
+}
+
+}
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/tools/source/stream/stream.cxx b/tools/source/stream/stream.cxx
index f807a56cf52f..2b7f8b08b1a3 100644
--- a/tools/source/stream/stream.cxx
+++ b/tools/source/stream/stream.cxx
@@ -1962,7 +1962,7 @@ OUString read_uInt16s_ToOUString(SvStream& rStrm, 
std::size_t nLen)
 {
 nLen = std::min(nLen, SAL_MAX_INT32);
 //limit allocation to size of file, but + 1 to set eof state
-nLen = std::min(nLen, (rStrm.remainingSize() + 2) / 2);
+nLen = o3tl::sanitizing_min(nLen, (rStrm.remainingSize() + 
2) / 2);
 //alloc a (ref-count 1) rtl_uString of the desired length.
 //rtl_String's buffer is uninitialized, except for null termination
 pStr = rtl_uString_alloc(sal::static_int_cast(nLen));
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/o3tl

2021-02-25 Thread Mike Kaganski (via logerrit)
 include/o3tl/unit_conversion.hxx |   10 --
 1 file changed, 4 insertions(+), 6 deletions(-)

New commits:
commit 27dd792d6db7012e3e819615e6ee937e2990beec
Author: Mike Kaganski 
AuthorDate: Thu Feb 25 10:41:45 2021 +0100
Commit: Mike Kaganski 
CommitDate: Thu Feb 25 17:22:59 2021 +0100

Use std::gcd

Change-Id: Ie24472aa2fd3bcda0ccb5945de38bd865b7d01aa
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111462
Tested-by: Jenkins
Reviewed-by: Mike Kaganski 

diff --git a/include/o3tl/unit_conversion.hxx b/include/o3tl/unit_conversion.hxx
index f377b16e8b10..434f2e50c1c8 100644
--- a/include/o3tl/unit_conversion.hxx
+++ b/include/o3tl/unit_conversion.hxx
@@ -15,6 +15,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -106,17 +107,14 @@ constexpr sal_Int64 MulDivSaturate(I n, sal_Int64 m, 
sal_Int64 d)
 return MulDiv(n, m, d);
 }
 
-// Greatest common divisor
-constexpr int gcd(sal_Int64 a, sal_Int64 b) { return b == 0 ? a : gcd(b, a % 
b); }
-
 // Packs integral multiplier and divisor for conversion from one unit to 
another
 struct m_and_d
 {
 sal_Int64 m; // multiplier
 sal_Int64 d; // divisor
 constexpr m_and_d(sal_Int64 _m, sal_Int64 _d)
-: m(_m / gcd(_m, _d)) // make sure to use smallest quotients here 
because
-, d(_d / gcd(_m, _d)) // they will be multiplied when building final 
table
+: m(_m / std::gcd(_m, _d)) // make sure to use smallest quotients here 
because
+, d(_d / std::gcd(_m, _d)) // they will be multiplied when building 
final table
 {
 assert(_m > 0 && _d > 0);
 }
@@ -139,7 +137,7 @@ template  constexpr auto prepareMDArray(const 
m_and_d ()[N])
 assert(mdBase[i].m < SAL_MAX_INT64 / mdBase[j].d);
 assert(mdBase[i].d < SAL_MAX_INT64 / mdBase[j].m);
 const sal_Int64 m = mdBase[i].m * mdBase[j].d, d = mdBase[i].d 
* mdBase[j].m;
-const sal_Int64 g = gcd(m, d);
+const sal_Int64 g = std::gcd(m, d);
 a[i][j] = m / g;
 a[j][i] = d / g;
 }
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/o3tl

2021-02-15 Thread Mike Kaganski (via logerrit)
 include/o3tl/unit_conversion.hxx |8 
 1 file changed, 4 insertions(+), 4 deletions(-)

New commits:
commit 76483d1348792a3d1c4c995ef0132ac79dfbc90f
Author: Mike Kaganski 
AuthorDate: Mon Feb 15 11:37:34 2021 +0300
Commit: Mike Kaganski 
CommitDate: Mon Feb 15 10:45:49 2021 +0100

Fix comments

Change-Id: Id3943df147a204391e206d663e0a71b43ded50a8
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110895
Tested-by: Jenkins
Reviewed-by: Mike Kaganski 

diff --git a/include/o3tl/unit_conversion.hxx b/include/o3tl/unit_conversion.hxx
index e43ecb557789..f377b16e8b10 100644
--- a/include/o3tl/unit_conversion.hxx
+++ b/include/o3tl/unit_conversion.hxx
@@ -50,8 +50,8 @@ enum class Length
 // If other categories of units would be needed (like time), a separate scoped 
enum
 // should be created, respective conversion array prepared in detail 
namespace, and
 // respective md(NewUnit, NewUnit) overload introduced, which would allow using
-// o3tl::convert() and o3tl::convertSanitize() with the new category in a 
type-safe
-// way, without mixing unrelated units.
+// o3tl::convert(), o3tl::convertSaturate() and o3tl::getConversionMulDiv() 
with the
+// new category in a type-safe way, without mixing unrelated units.
 
 namespace detail
 {
@@ -206,7 +206,7 @@ template  constexpr auto convert(N 
n, U from, U to)
 }
 
 // Returns nDefault if intermediate multiplication overflows sal_Int64 (only 
for integral types).
-// On return, bOverflow indicates if overflow happened.
+// On return, bOverflow indicates if overflow happened. nDefault is returned 
when overflow occurs.
 template 
 constexpr auto convert(N n, U from, U to, bool& bOverflow, sal_Int64 nDefault 
= 0)
 {
@@ -214,7 +214,7 @@ constexpr auto convert(N n, U from, U to, bool& bOverflow, 
sal_Int64 nDefault =
 }
 
 // Conversion with saturation (only for integral types). For too large input 
returns SAL_MAX_INT64.
-// When intermediate multiplication would overflow, but otherwise result in in 
sal_Int64 range, the
+// When intermediate multiplication would overflow, but the end result is in 
sal_Int64 range, the
 // precision is decreased because of inversion of multiplication and division.
 template  constexpr auto convertSaturate(N n, U from, 
U to)
 {
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/o3tl

2021-02-14 Thread Mike Kaganski (via logerrit)
 include/o3tl/unit_conversion.hxx |   12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

New commits:
commit 8ec3222d47ef5a13921576569a700785378916a8
Author: Mike Kaganski 
AuthorDate: Sun Feb 14 22:13:51 2021 +0300
Commit: Mike Kaganski 
CommitDate: Mon Feb 15 07:47:25 2021 +0100

Do not initialize array at each function call

The function-local symbol prevented inlining in some cases, and needed
a memcpy of 3200 bytes on each call.

Change-Id: If2bd59d4bfc2a91e891cb0975847b7afebfbca23
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110888
Tested-by: Jenkins
Reviewed-by: Mike Kaganski 

diff --git a/include/o3tl/unit_conversion.hxx b/include/o3tl/unit_conversion.hxx
index 17dd5ae12293..e43ecb557789 100644
--- a/include/o3tl/unit_conversion.hxx
+++ b/include/o3tl/unit_conversion.hxx
@@ -178,16 +178,16 @@ constexpr m_and_d mdBaseLen[] = {
 static_assert(SAL_N_ELEMENTS(mdBaseLen) == static_cast(Length::count),
   "mdBaseL must have an entry for each unit in o3tl::Length");
 
+// The resulting multipliers and divisors array
+constexpr auto aLengthMDArray = prepareMDArray(mdBaseLen);
+
 // an overload taking Length
 constexpr sal_Int64 md(Length i, Length j)
 {
-// The resulting multipliers and divisors array
-constexpr auto aMDArray = prepareMDArray(mdBaseLen);
-
 const int nI = static_cast(i), nJ = static_cast(j);
-assert(nI >= 0 && o3tl::make_unsigned(nI) < aMDArray.size());
-assert(nJ >= 0 && o3tl::make_unsigned(nJ) < aMDArray.size());
-return aMDArray[nI][nJ];
+assert(nI >= 0 && o3tl::make_unsigned(nI) < aLengthMDArray.size());
+assert(nJ >= 0 && o3tl::make_unsigned(nJ) < aLengthMDArray.size());
+return aLengthMDArray[nI][nJ];
 }
 
 // here might go overloads of md() taking other units ...
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/o3tl

2021-01-16 Thread Julien Nabet (via logerrit)
 include/o3tl/safeint.hxx |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

New commits:
commit ebb0ac4c922b51191979ca376f7c7d7581ace62e
Author: Julien Nabet 
AuthorDate: Fri Jan 15 10:01:51 2021 +0100
Commit: Julien Nabet 
CommitDate: Sat Jan 16 11:19:23 2021 +0100

Fix o3tl::checked_multiply for Raspberry pi 4b

usr/bin/ld : /usr/bin/ld: Erreur DWARF: ne peut repérer la spécification de 
variable au décalage 8953
/usr/bin/ld: Erreur DWARF: ne peut repérer la spécification de variable au 
décalage 93da
/usr/bin/ld: Erreur DWARF: ne peut repérer la spécification de variable au 
décalage 967a
/usr/bin/ld: Erreur DWARF: ne peut repérer la spécification de variable au 
décalage 991a
/home/pi/lo/libreoffice/workdir/CxxObject/sw/source/filter/xml/xmlimp.o : 
dans la fonction « bool o3tl::checked_multiply(long long, long long, 
long long&) » :
/home/pi/lo/libreoffice/include/o3tl/safeint.hxx:121 : référence indéfinie 
vers « __mulodi4 »
/usr/bin/ld : /home/pi/lo/libreoffice/include/o3tl/safeint.hxx:121 : 
référence indéfinie vers « __mulodi4 »
/usr/bin/ld : /home/pi/lo/libreoffice/include/o3tl/safeint.hxx:121 : 
référence indéfinie vers « __mulodi4 »
/usr/bin/ld : /home/pi/lo/libreoffice/include/o3tl/safeint.hxx:121 : 
référence indéfinie vers « __mulodi4 »
clang: error: linker command failed with exit code 1 (use -v to see 
invocation)
make[1]: *** [/home/pi/lo/libreoffice/sw/Library_sw.mk:20 : 
/home/pi/lo/libreoffice/instdir/program/libswlo.so] Erreur 1

DWARF Error: can't find spec of var at offset 8953

undefined reference to "__mulodi4"

Change-Id: I1c88a1567e25370eb5759912ea4918d7183f3786
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109322
Tested-by: Jenkins
Reviewed-by: Julien Nabet 

diff --git a/include/o3tl/safeint.hxx b/include/o3tl/safeint.hxx
index 0ed36c910fa3..9df92ea1a9d1 100644
--- a/include/o3tl/safeint.hxx
+++ b/include/o3tl/safeint.hxx
@@ -113,7 +113,7 @@ template inline bool checked_sub(T a, T b, T& 
result)
 return !msl::utilities::SafeSubtract(a, b, result);
 }
 
-#elif (defined __GNUC__ && !defined __clang__) || 
(__has_builtin(__builtin_mul_overflow) && !(defined ANDROID && defined 
__clang__) && !(defined(__clang__) && defined(__i386__)))
+#elif (defined __GNUC__ && !defined __clang__) || 
(__has_builtin(__builtin_mul_overflow) && !(defined ANDROID && defined 
__clang__) && !(defined(__clang__) && (defined(__arm__) || defined(__i386__
 // 32-bit clang fails with undefined reference to `__mulodi4'
 
 template inline bool checked_multiply(T a, T b, T& result)
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/o3tl

2021-01-12 Thread Stephan Bergmann (via logerrit)
 include/o3tl/lru_map.hxx |1 +
 1 file changed, 1 insertion(+)

New commits:
commit e24cc814b5b6e50967116cb3908e4bf56b7aee4b
Author: Stephan Bergmann 
AuthorDate: Tue Jan 12 15:50:10 2021 +0100
Commit: Stephan Bergmann 
CommitDate: Wed Jan 13 07:37:30 2021 +0100

Missing include (for std::min)

Change-Id: I44eebee0149d7e890aeff715dd7ae0005c45378d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109179
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/o3tl/lru_map.hxx b/include/o3tl/lru_map.hxx
index 96fb3161782d..ce5a078bc352 100644
--- a/include/o3tl/lru_map.hxx
+++ b/include/o3tl/lru_map.hxx
@@ -11,6 +11,7 @@
 #ifndef INCLUDED_O3TL_LRU_MAP_HXX
 #define INCLUDED_O3TL_LRU_MAP_HXX
 
+#include 
 #include 
 #include 
 #include 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/o3tl

2020-12-04 Thread Jeff Law (via logerrit)
 include/o3tl/lru_map.hxx |1 +
 1 file changed, 1 insertion(+)

New commits:
commit 8830cf86b146b1252ac37f351a23246088d569b0
Author: Jeff Law 
AuthorDate: Tue Nov 3 08:05:03 2020 -0700
Commit: Caolán McNamara 
CommitDate: Fri Dec 4 12:04:15 2020 +0100

include cstddef for gcc11

Change-Id: I2f845ce9bb660ad6c1eea80ea81dd71add2c0db1
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107191
Tested-by: Jenkins
Reviewed-by: Caolán McNamara 

diff --git a/include/o3tl/lru_map.hxx b/include/o3tl/lru_map.hxx
index c7132fd079c4..96fb3161782d 100644
--- a/include/o3tl/lru_map.hxx
+++ b/include/o3tl/lru_map.hxx
@@ -14,6 +14,7 @@
 #include 
 #include 
 #include 
+#include 
 
 namespace o3tl
 {
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/o3tl

2020-11-26 Thread Andrea Gelmini (via logerrit)
 include/o3tl/safeint.hxx |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

New commits:
commit 2e93fb2ff592719dcfe4e073cfd1b1240692938e
Author: Andrea Gelmini 
AuthorDate: Thu Nov 26 08:05:02 2020 +0100
Commit: Julien Nabet 
CommitDate: Thu Nov 26 18:24:09 2020 +0100

Fix typo

Change-Id: I6dbac66a590cf0cc388796bed918d68800a1537e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/106652
Tested-by: Jenkins
Reviewed-by: Julien Nabet 

diff --git a/include/o3tl/safeint.hxx b/include/o3tl/safeint.hxx
index a5c212244c7c..0ed36c910fa3 100644
--- a/include/o3tl/safeint.hxx
+++ b/include/o3tl/safeint.hxx
@@ -236,7 +236,7 @@ make_unsigned(T value)
 
 // An implicit conversion from T2 to T1, useful in places where an explicit 
conversion from T2 to
 // T1 is needed (e.g., in list initialization, if the implicit conversion 
would be narrowing) but
-// tools like -fsanitize=implict-conversion should still be able to detect 
truncation:
+// tools like -fsanitize=implicit-conversion should still be able to detect 
truncation:
 template constexpr T1 narrowing(T2 value) { return 
value; }
 
 }
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/o3tl vcl/win

2020-11-25 Thread Stephan Bergmann (via logerrit)
 include/o3tl/safeint.hxx   |5 +
 vcl/win/gdi/DWriteTextRenderer.cxx |5 -
 vcl/win/gdi/winlayout.cxx  |7 +--
 3 files changed, 14 insertions(+), 3 deletions(-)

New commits:
commit b1404b5919f8c18bde715f68b229d2c030de5b2a
Author: Stephan Bergmann 
AuthorDate: Wed Nov 25 11:06:00 2020 +0100
Commit: Stephan Bergmann 
CommitDate: Wed Nov 25 14:08:20 2020 +0100

-Wc++11-narrowing (clang-cl)

MSVC seems not to mind, but a Windows 64-bit build with clang-cl fails with
"error: non-constant-expression cannot be narrowed from type 'tools::Long' 
(aka
'long long') to 'LONG' (aka 'long') in initializer list".  But adding 
explicit
casts would have the downside of preventing tools like
-fsanitize=implict-conversion (if we ever use that on Windows) from 
detecting
truncation, so introduce o3tl::narrowing.

Change-Id: Ia33a9ae4d8134b5ad0c8b7cf6812fbdd625ca89e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/106577
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/o3tl/safeint.hxx b/include/o3tl/safeint.hxx
index 6d8d1304fdf3..a5c212244c7c 100644
--- a/include/o3tl/safeint.hxx
+++ b/include/o3tl/safeint.hxx
@@ -234,6 +234,11 @@ make_unsigned(T value)
 return value;
 }
 
+// An implicit conversion from T2 to T1, useful in places where an explicit 
conversion from T2 to
+// T1 is needed (e.g., in list initialization, if the implicit conversion 
would be narrowing) but
+// tools like -fsanitize=implict-conversion should still be able to detect 
truncation:
+template constexpr T1 narrowing(T2 value) { return 
value; }
+
 }
 
 #endif
diff --git a/vcl/win/gdi/DWriteTextRenderer.cxx 
b/vcl/win/gdi/DWriteTextRenderer.cxx
index da8eab0e6ce0..185925ae7967 100644
--- a/vcl/win/gdi/DWriteTextRenderer.cxx
+++ b/vcl/win/gdi/DWriteTextRenderer.cxx
@@ -30,6 +30,7 @@
 #include 
 
 #include 
+#include 
 #include 
 
 namespace
@@ -190,7 +191,9 @@ bool D2DWriteTextOutRenderer::Ready() const
 
 HRESULT D2DWriteTextOutRenderer::BindDC(HDC hDC, tools::Rectangle const & 
rRect)
 {
-RECT const rc = { rRect.Left(), rRect.Top(), rRect.Right(), rRect.Bottom() 
};
+RECT const rc = {
+o3tl::narrowing(rRect.Left()), 
o3tl::narrowing(rRect.Top()),
+o3tl::narrowing(rRect.Right()), 
o3tl::narrowing(rRect.Bottom()) };
 return CHECKHR(mpRT->BindDC(hDC, ));
 }
 
diff --git a/vcl/win/gdi/winlayout.cxx b/vcl/win/gdi/winlayout.cxx
index 7863a3c353d2..398196438fb7 100644
--- a/vcl/win/gdi/winlayout.cxx
+++ b/vcl/win/gdi/winlayout.cxx
@@ -21,6 +21,8 @@
 #include 
 
 #include 
+
+#include 
 #include 
 #include 
 #include 
@@ -594,8 +596,9 @@ void WinSalGraphics::DrawTextLayout(const GenericSalLayout& 
rLayout)
 // we are making changes to the DC, make sure we got a new one
 assert(aDC->getCompatibleHDC() != hDC);
 
-RECT aWinRect = { aRect.Left(), aRect.Top(), aRect.Left() + 
aRect.GetWidth(),
-  aRect.Top() + aRect.GetHeight() };
+RECT aWinRect = { o3tl::narrowing(aRect.Left()), 
o3tl::narrowing(aRect.Top()),
+  o3tl::narrowing(aRect.Left() + 
aRect.GetWidth()),
+  o3tl::narrowing(aRect.Top() + 
aRect.GetHeight()) };
 ::FillRect(aDC->getCompatibleHDC(), ,
static_cast(::GetStockObject(WHITE_BRUSH)));
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/o3tl

2020-10-29 Thread Stephan Bergmann (via logerrit)
 include/o3tl/cppunittraitshelper.hxx |3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

New commits:
commit c8b93a478dc420398b3f70724422a551bb743a70
Author: Stephan Bergmann 
AuthorDate: Thu Oct 29 08:09:50 2020 +0100
Commit: Stephan Bergmann 
CommitDate: Thu Oct 29 09:17:55 2020 +0100

Use the underlying type of char16_t

Change-Id: I5f48f1f3dc379cc57cfeac473f80bec4c4bc38af
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104989
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/o3tl/cppunittraitshelper.hxx 
b/include/o3tl/cppunittraitshelper.hxx
index d9f75a61b4c8..2a6fb8836238 100644
--- a/include/o3tl/cppunittraitshelper.hxx
+++ b/include/o3tl/cppunittraitshelper.hxx
@@ -12,6 +12,7 @@
 
 #include 
 
+#include 
 #include 
 
 #include 
@@ -19,7 +20,7 @@
 // ostream << char16_t is deleted since C++20 (but just keep outputting 
numeric values):
 template <> inline std::string 
CppUnit::assertion_traits::toString(char16_t const& x)
 {
-return assertion_traits::toString(unsigned(x));
+return 
assertion_traits::toString(std::uint_least16_t(x));
 }
 
 #endif
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/o3tl include/svx svx/source

2020-10-28 Thread Noel Grandin (via logerrit)
 include/o3tl/sorted_vector.hxx |1 +
 include/svx/fmtools.hxx|4 ++--
 svx/source/form/fmshimp.cxx|2 +-
 3 files changed, 4 insertions(+), 3 deletions(-)

New commits:
commit ce0f8cff3e2e42bf6ff0968c3a6a9efb71ec00d1
Author: Noel Grandin 
AuthorDate: Tue Oct 27 21:10:39 2020 +0200
Commit: Noel Grandin 
CommitDate: Wed Oct 28 07:23:39 2020 +0100

std::set->o3tl::sorted_vector in InterfaceBag

Change-Id: I28ecffdcf6c97f9153e62974bf76b972452747eb
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104901
Tested-by: Jenkins
Reviewed-by: Noel Grandin 

diff --git a/include/o3tl/sorted_vector.hxx b/include/o3tl/sorted_vector.hxx
index 803a044535e8..508fe61cc03e 100644
--- a/include/o3tl/sorted_vector.hxx
+++ b/include/o3tl/sorted_vector.hxx
@@ -45,6 +45,7 @@ public:
 typedef typename std::vector::const_reverse_iterator 
const_reverse_iterator;
 typedef typename std::vector::difference_type difference_type;
 typedef typename std::vector::size_type size_type;
+typedef Value value_type;
 
 constexpr sorted_vector( std::initializer_list init )
 : m_vector(init)
diff --git a/include/svx/fmtools.hxx b/include/svx/fmtools.hxx
index f0fba4e0f32a..90eb6d74c49c 100644
--- a/include/svx/fmtools.hxx
+++ b/include/svx/fmtools.hxx
@@ -30,7 +30,7 @@
 
 #include 
 #include 
-
+#include 
 #include 
 
 namespace com::sun::star::beans { class XPropertySet; }
@@ -168,7 +168,7 @@ bool isRowSetAlive(const css::uno::Reference< 
css::uno::XInterface>& _rxRowSet);
 // checks if the css::sdbcx::XColumnsSupplier provided by _rxRowSet 
supplies any columns
 
 
-typedef ::std::set< css::uno::Reference< css::uno::XInterface > > InterfaceBag;
+typedef ::o3tl::sorted_vector< css::uno::Reference< css::uno::XInterface > > 
InterfaceBag;
 
 #endif // INCLUDED_SVX_FMTOOLS_HXX
 
diff --git a/svx/source/form/fmshimp.cxx b/svx/source/form/fmshimp.cxx
index d7f25ec073bc..df80dae12a11 100644
--- a/svx/source/form/fmshimp.cxx
+++ b/svx/source/form/fmshimp.cxx
@@ -2603,7 +2603,7 @@ void FmXFormShell::impl_RemoveElement_nothrow_Lock(const 
Reference&
 }
 }
 
-InterfaceBag::iterator wasSelectedPos = m_aCurrentSelection.find( Element 
);
+auto wasSelectedPos = m_aCurrentSelection.find( Element );
 if ( wasSelectedPos != m_aCurrentSelection.end() )
 m_aCurrentSelection.erase( wasSelectedPos );
 }
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/o3tl

2020-09-21 Thread Caolán McNamara (via logerrit)
 include/o3tl/deleter.hxx |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

New commits:
commit 649a625cb585af244a3d5e57911670784fa87c40
Author: Caolán McNamara 
AuthorDate: Mon Sep 21 11:37:44 2020 +0100
Commit: Caolán McNamara 
CommitDate: Mon Sep 21 13:20:53 2020 +0200

missing identifier

Change-Id: Id3a41a7832299d51776ccd9ea008092c0ee62aab
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/103093
Tested-by: Jenkins
Reviewed-by: Caolán McNamara 

diff --git a/include/o3tl/deleter.hxx b/include/o3tl/deleter.hxx
index 72d13d086de1..a886acb03d3c 100644
--- a/include/o3tl/deleter.hxx
+++ b/include/o3tl/deleter.hxx
@@ -32,7 +32,7 @@ template struct default_delete
 {
 delete p;
 }
-catch (const css::uno::Exception&)
+catch (const css::uno::Exception& ex)
 {
 SAL_WARN("vcl.app", "Fatal exception: " << exceptionToString(ex));
 std::terminate();
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/o3tl include/svx svx/source

2020-09-13 Thread Noel Grandin (via logerrit)
 include/o3tl/sorted_vector.hxx  |   17 +++--
 include/svx/polypolygoneditor.hxx   |7 ---
 include/svx/svdmark.hxx |4 ++--
 svx/source/inc/fmvwimp.hxx  |1 +
 svx/source/svdraw/polypolygoneditor.cxx |   12 ++--
 svx/source/svdraw/svdglev.cxx   |2 +-
 6 files changed, 29 insertions(+), 14 deletions(-)

New commits:
commit 4059583469c168c553d0529684caba6b281827d1
Author: Noel Grandin 
AuthorDate: Sat Sep 12 20:10:17 2020 +0200
Commit: Noel Grandin 
CommitDate: Sun Sep 13 08:13:59 2020 +0200

std::set->o3tl::sorted_vector in svx

Change-Id: I86154a8ddf885ea23ff29e4df1b67e7501b9165b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/102536
Tested-by: Jenkins
Reviewed-by: Noel Grandin 

diff --git a/include/o3tl/sorted_vector.hxx b/include/o3tl/sorted_vector.hxx
index 28ef75817fa7..803a044535e8 100644
--- a/include/o3tl/sorted_vector.hxx
+++ b/include/o3tl/sorted_vector.hxx
@@ -42,6 +42,7 @@ private:
 typedef typename std::vector::iterator  iterator;
 public:
 typedef typename std::vector::const_iterator const_iterator;
+typedef typename std::vector::const_reverse_iterator 
const_reverse_iterator;
 typedef typename std::vector::difference_type difference_type;
 typedef typename std::vector::size_type size_type;
 
@@ -98,9 +99,9 @@ public:
 }
 
 // like C++ 2011: erase with const_iterator (doesn't change sort order)
-void erase(const_iterator const& position)
+const_iterator erase(const_iterator const& position)
 {   // C++98 has vector::erase(iterator), so call that
-m_vector.erase(m_vector.begin() + (position - m_vector.begin()));
+return m_vector.erase(m_vector.begin() + (position - 
m_vector.begin()));
 }
 
 void erase(const_iterator const& first, const_iterator const& last)
@@ -159,6 +160,18 @@ public:
 return m_vector.end();
 }
 
+// Only return a const iterator, so that the vector cannot be directly 
updated.
+const_reverse_iterator rbegin() const
+{
+return m_vector.rbegin();
+}
+
+// Only return a const iterator, so that the vector cannot be directly 
updated.
+const_reverse_iterator rend() const
+{
+return m_vector.rend();
+}
+
 const Value& front() const
 {
 return m_vector.front();
diff --git a/include/svx/polypolygoneditor.hxx 
b/include/svx/polypolygoneditor.hxx
index e8b6138dffa4..347bbc4a92a5 100644
--- a/include/svx/polypolygoneditor.hxx
+++ b/include/svx/polypolygoneditor.hxx
@@ -26,6 +26,7 @@
 
 #include 
 #include 
+#include 
 
 namespace sdr
 {
@@ -41,15 +42,15 @@ public:
 /** returns true if the B2DPolyPolygon was changed.
 Warning: B2DPolyPolygon can be empty after this operation!
 */
-bool DeletePoints( const std::set< sal_uInt16 >& rAbsPoints );
+bool DeletePoints( const o3tl::sorted_vector< sal_uInt16 >& rAbsPoints );
 
 /** returns true if the B2DPolyPolygon was changed.
 */
-bool SetSegmentsKind(SdrPathSegmentKind eKind, const std::set< sal_uInt16 
>& rAbsPoints);
+bool SetSegmentsKind(SdrPathSegmentKind eKind, const o3tl::sorted_vector< 
sal_uInt16 >& rAbsPoints);
 
 /** returns true if the B2DPolyPolygon was changed.
 */
-bool SetPointsSmooth( basegfx::B2VectorContinuity eFlags, const std::set< 
sal_uInt16 >& rAbsPoints);
+bool SetPointsSmooth( basegfx::B2VectorContinuity eFlags, const 
o3tl::sorted_vector< sal_uInt16 >& rAbsPoints);
 
 /** Outputs the relative position ( polygon number and point number in 
that polygon ) from the absolute point number.
 False is returned if the given absolute point is greater not inside 
this B2DPolyPolygon
diff --git a/include/svx/svdmark.hxx b/include/svx/svdmark.hxx
index f5f9c7b539d5..1b121a58f86e 100644
--- a/include/svx/svdmark.hxx
+++ b/include/svx/svdmark.hxx
@@ -21,12 +21,12 @@
 #define INCLUDED_SVX_SVDMARK_HXX
 
 #include 
+#include 
 #include 
 #include 
 #include 
 
 #include 
-#include 
 #include 
 
 namespace tools { class Rectangle; }
@@ -35,7 +35,7 @@ class SdrObjList;
 class SdrObject;
 class SdrPageView;
 
-typedef std::set SdrUShortCont;
+typedef o3tl::sorted_vector SdrUShortCont;
 
 
 /**
diff --git a/svx/source/inc/fmvwimp.hxx b/svx/source/inc/fmvwimp.hxx
index 1e6a01dab0cb..278c4eda597b 100644
--- a/svx/source/inc/fmvwimp.hxx
+++ b/svx/source/inc/fmvwimp.hxx
@@ -23,6 +23,7 @@
 
 #include 
 #include 
+#include 
 
 #include 
 #include 
diff --git a/svx/source/svdraw/polypolygoneditor.cxx 
b/svx/source/svdraw/polypolygoneditor.cxx
index 1f82f0436544..b3f6d3bc5175 100644
--- a/svx/source/svdraw/polypolygoneditor.cxx
+++ b/svx/source/svdraw/polypolygoneditor.cxx
@@ -30,11 +30,11 @@ PolyPolygonEditor::PolyPolygonEditor( const 
basegfx::B2DPolyPolygon& rPolyPolygo
 {
 }
 
-bool PolyPolygonEditor::DeletePoints( const std::set< sal_uInt16 >& rAbsPoints 
)
+bool PolyPolygonEditor::DeletePoints( const 

[Libreoffice-commits] core.git: include/o3tl o3tl/qa

2020-02-22 Thread Stephan Bergmann (via logerrit)
 include/o3tl/span.hxx |7 ---
 o3tl/qa/test-span.cxx |6 --
 2 files changed, 13 deletions(-)

New commits:
commit 6fbfad6b00e8c35346ee59cd32a0d7ccc0d8c19c
Author: Stephan Bergmann 
AuthorDate: Sat Feb 22 17:29:15 2020 +0100
Commit: Stephan Bergmann 
CommitDate: Sat Feb 22 19:41:50 2020 +0100

Adapt o3tl::span to removal of std::span::cbegin et al

 "span::cbegin/cend methods 
produce
different results than std::[ranges::]cbegin/cend", as implemented now in
 "libstdc++: Remove 
std::span::cbegin
and std::span::cend (LWG 3320)".

Turns out we only used the removed member functions in 
o3tl/qa/test-span.cxx.

Change-Id: I6c73797594b4e0e753a88840033d54961e271df5
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/89261
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/o3tl/span.hxx b/include/o3tl/span.hxx
index b19d2d847ac7..8af8ba846b65 100644
--- a/include/o3tl/span.hxx
+++ b/include/o3tl/span.hxx
@@ -62,18 +62,11 @@ public:
 constexpr iterator begin() const noexcept { return data_; }
 constexpr iterator end() const noexcept { return begin() + size(); }
 
-constexpr const_iterator cbegin() const noexcept { return begin(); }
-constexpr const_iterator cend() const noexcept { return end(); }
-
 reverse_iterator rbegin() const noexcept
 { return reverse_iterator(end()); }
 reverse_iterator rend() const noexcept
 { return reverse_iterator(begin()); }
 
-constexpr const_reverse_iterator crbegin() const noexcept
-{ return rbegin(); }
-constexpr const_reverse_iterator crend() const noexcept { return rend(); }
-
 constexpr size_type size() const noexcept { return size_; }
 
 constexpr reference operator [](size_type pos) const {
diff --git a/o3tl/qa/test-span.cxx b/o3tl/qa/test-span.cxx
index 3cb78ace1db2..26eedfc21938 100644
--- a/o3tl/qa/test-span.cxx
+++ b/o3tl/qa/test-span.cxx
@@ -34,15 +34,9 @@ private:
 CPPUNIT_ASSERT_EQUAL(1, *v.begin());
 CPPUNIT_ASSERT_EQUAL(
 o3tl::span::difference_type(3), v.end() - v.begin());
-CPPUNIT_ASSERT_EQUAL(1, *v.cbegin());
-CPPUNIT_ASSERT_EQUAL(
-o3tl::span::difference_type(3), v.cend() - v.cbegin());
 CPPUNIT_ASSERT_EQUAL(3, *v.rbegin());
 CPPUNIT_ASSERT_EQUAL(
 o3tl::span::difference_type(3), v.rend() - v.rbegin());
-CPPUNIT_ASSERT_EQUAL(3, *v.crbegin());
-CPPUNIT_ASSERT_EQUAL(
-o3tl::span::difference_type(3), v.crend() - v.crbegin());
 CPPUNIT_ASSERT_EQUAL(std::size_t(3), v.size());
 CPPUNIT_ASSERT(!v.empty());
 CPPUNIT_ASSERT_EQUAL(2, v[1]);
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/o3tl sc/inc sc/source stoc/source sw/inc sw/source vcl/inc

2020-01-31 Thread Noel Grandin (via logerrit)
 include/o3tl/sorted_vector.hxx  |5 +
 sc/inc/externalrefmgr.hxx   |   11 ++-
 sc/inc/recursionhelper.hxx  |8 
 sc/source/core/data/formulacell.cxx |4 ++--
 sc/source/core/tool/recursionhelper.cxx |2 +-
 sc/source/filter/inc/xetable.hxx|4 ++--
 stoc/source/invocation_adapterfactory/iafactory.cxx |5 +++--
 sw/inc/swwait.hxx   |4 ++--
 sw/source/core/doc/docnew.cxx   |4 ++--
 vcl/inc/graphic/Manager.hxx |4 ++--
 vcl/inc/salusereventlist.hxx|   10 ++
 vcl/inc/win/winlayout.hxx   |3 ++-
 12 files changed, 29 insertions(+), 35 deletions(-)

New commits:
commit 1a12861e01acd7a0c879a1124dd9ed4297a03dca
Author: Noel Grandin 
AuthorDate: Sat Feb 1 08:29:21 2020 +0200
Commit: Noel Grandin 
CommitDate: Sat Feb 1 08:19:54 2020 +0100

std::unordered_set -> o3tl::sorted_vector

which is much better for CPU cache, since the representation is more
compact, and since we almost always do insert() in pointer order,
there is surprisingly little sorting

Also add a count() method for compatibility with std::set and the
proposed std::flat_set

Change-Id: I2a3211dc59919cfec5cac1497530a4c3600d50ca
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87793
Tested-by: Jenkins
Reviewed-by: Noel Grandin 

diff --git a/include/o3tl/sorted_vector.hxx b/include/o3tl/sorted_vector.hxx
index 088f5a2aa214..28ef75817fa7 100644
--- a/include/o3tl/sorted_vector.hxx
+++ b/include/o3tl/sorted_vector.hxx
@@ -198,6 +198,11 @@ public:
 return (ret.second) ? ret.first : m_vector.end();
 }
 
+size_type count(const Value& v) const
+{
+return find(v) != end() ? 1 : 0;
+}
+
 bool operator==(const sorted_vector & other) const
 {
 return m_vector == other.m_vector;
diff --git a/sc/inc/externalrefmgr.hxx b/sc/inc/externalrefmgr.hxx
index b95d6d1a0fd1..128feab61894 100644
--- a/sc/inc/externalrefmgr.hxx
+++ b/sc/inc/externalrefmgr.hxx
@@ -39,6 +39,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 class ScTokenArray;
@@ -381,14 +382,6 @@ public:
 LinkListener();
 virtual ~LinkListener() COVERITY_NOEXCEPT_FALSE = 0;
 virtual void notify(sal_uInt16 nFileId, LinkUpdateType eType) = 0;
-
-struct Hash
-{
-size_t operator() (const LinkListener* p) const
-{
-return reinterpret_cast(p);
-}
-};
 };
 
 /**
@@ -421,7 +414,7 @@ private:
 
 typedef std::unordered_map 
NumFmtMap;
 
-typedef std::unordered_set  
LinkListeners;
+typedef o3tl::sorted_vector 
LinkListeners;
 typedef std::unordered_map  
LinkListenerMap;
 
 public:
diff --git a/sc/inc/recursionhelper.hxx b/sc/inc/recursionhelper.hxx
index 9988a676203b..f741aa8bab67 100644
--- a/sc/inc/recursionhelper.hxx
+++ b/sc/inc/recursionhelper.hxx
@@ -25,7 +25,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 
 class ScFormulaCell;
 
@@ -65,7 +65,7 @@ class ScRecursionHelper
 boolbConverging;
 boolbGroupsIndependent;
 std::vector< ScFormulaCell* >   aTemporaryGroupCells;
-std::unordered_set< ScFormulaCellGroup* >* pFGSet;
+o3tl::sorted_vector< ScFormulaCellGroup* >* pFGSet;
 
 void Init();
 void ResetIteration();
@@ -120,7 +120,7 @@ public:
 void AddTemporaryGroupCell(ScFormulaCell* cell);
 void CleanTemporaryGroupCells();
 
-void SetFormulaGroupSet(std::unordered_set* pSet) { 
pFGSet = pSet; }
+void SetFormulaGroupSet(o3tl::sorted_vector* pSet) { 
pFGSet = pSet; }
 bool HasFormulaGroupSet() { return pFGSet != nullptr; }
 bool CheckFGIndependence(ScFormulaCellGroup* pFG);
 void SetGroupsIndependent(bool bSet) { bGroupsIndependent = bSet; }
@@ -157,7 +157,7 @@ class ScCheckIndependentFGGuard
 public:
 ScCheckIndependentFGGuard() = delete;
 ScCheckIndependentFGGuard(ScRecursionHelper& rRecursionHelper,
-  std::unordered_set* pSet);
+  o3tl::sorted_vector* pSet);
 ~ScCheckIndependentFGGuard();
 
 bool AreGroupsIndependent();
diff --git a/sc/source/core/data/formulacell.cxx 
b/sc/source/core/data/formulacell.cxx
index c39b21341bd5..e1cb04eb3ad2 100644
--- a/sc/source/core/data/formulacell.cxx
+++ b/sc/source/core/data/formulacell.cxx
@@ -4717,7 +4717,7 @@ bool 
ScFormulaCell::CheckComputeDependencies(sc::FormulaLogger::GroupScope& rSco
 }
 
 static SCCOL lcl_probeLeftOrRightFGs(const ScFormulaCellGroupRef& xGroup, 
const ScDocument& rDoc,
- std::unordered_set& 
rFGSet,
+ 

[Libreoffice-commits] core.git: include/o3tl sw/source

2020-01-26 Thread Tomaž Vajngerl (via logerrit)
 include/o3tl/vector_utils.hxx|   27 +++
 sw/source/core/access/AccessibilityCheck.cxx |   11 ++-
 2 files changed, 29 insertions(+), 9 deletions(-)

New commits:
commit af29884072817481273c03373899624933fd567a
Author: Tomaž Vajngerl 
AuthorDate: Sun Jan 26 09:38:40 2020 +0100
Commit: Tomaž Vajngerl 
CommitDate: Sun Jan 26 13:53:21 2020 +0100

move "remove duplicates" for a vector to o3tl/vector_utils.hxx

Change-Id: I9ecf95a2bf975912b7029cdfb459a9ebc159c75d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87429
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl 

diff --git a/include/o3tl/vector_utils.hxx b/include/o3tl/vector_utils.hxx
new file mode 100644
index ..dc6d80a9ffbc
--- /dev/null
+++ b/include/o3tl/vector_utils.hxx
@@ -0,0 +1,27 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#pragma once
+
+#include 
+
+namespace o3tl
+{
+// removes duplicated elements in a vector
+template  void remove_duplicates(std::vector& rVector)
+{
+std::unordered_set aSet;
+auto aEnd = std::copy_if(rVector.begin(), rVector.end(), rVector.begin(),
+ [](T const& rElement) { return 
aSet.insert(rElement).second; });
+rVector.erase(aEnd, rVector.end());
+}
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/access/AccessibilityCheck.cxx 
b/sw/source/core/access/AccessibilityCheck.cxx
index 0d8c1eee4aab..bf1660d073c1 100644
--- a/sw/source/core/access/AccessibilityCheck.cxx
+++ b/sw/source/core/access/AccessibilityCheck.cxx
@@ -30,6 +30,7 @@
 #include 
 #include 
 #include 
+#include 
 
 namespace sw
 {
@@ -45,14 +46,6 @@ lclAddIssue(sfx::AccessibilityIssueCollection& 
rIssueCollection, OUString const&
 return pIssue;
 }
 
-template  void removeDuplicates(std::vector& aVector)
-{
-std::unordered_set aSet;
-auto end = std::copy_if(aVector.begin(), aVector.end(), aVector.begin(),
-[](T const& rElement) { return 
aSet.insert(rElement).second; });
-aVector.erase(end, aVector.end());
-}
-
 class BaseCheck
 {
 protected:
@@ -518,7 +511,7 @@ public:
 }
 if (!aFormattings.empty())
 {
-removeDuplicates(aFormattings);
+o3tl::remove_duplicates(aFormattings);
 auto pIssue
 = lclAddIssue(m_rIssueCollection, 
SwResId(STR_TEXT_FORMATTING_CONVEYS_MEANING),
   sfx::AccessibilityIssueID::TEXT_FORMATTING);
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/o3tl

2019-12-07 Thread Stephan Bergmann (via logerrit)
 include/o3tl/optional.hxx |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

New commits:
commit b9f43acf9c4f2f800456bb19a5fd0879541cabc6
Author: Stephan Bergmann 
AuthorDate: Fri Dec 6 23:28:33 2019 +0100
Commit: Stephan Bergmann 
CommitDate: Sat Dec 7 13:51:56 2019 +0100

Better not use constexpr here

With a locally modified include/o3tl/optional.hxx to always pick the
boost::optional branch, to prepare 

"Fix more new dependencies on boost_headers", that constexpr caused

> In file included from idlc/source/errorhandler.cxx:20:
> In file included from idlc/inc/errorhandler.hxx:23:
> In file included from idlc/inc/astexpression.hxx:27:
> include/o3tl/optional.hxx:28:23: error: constexpr variable cannot have 
non-literal type 'const boost::none_t'
> inline constexpr auto nullopt = boost::none;
>   ^
> workdir/UnpackedTarball/boost/boost/none_t.hpp:29:8: note: 'none_t' is 
not literal because it is not an aggregate and has no constexpr constructors 
other than copy or move constructors
> struct none_t
>^

at least with recent Clang 10 trunk and --without-system-boost.

Change-Id: I679a6ca5d135d3f5571845a15afe20d28a1f9039
Reviewed-on: https://gerrit.libreoffice.org/84673
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/o3tl/optional.hxx b/include/o3tl/optional.hxx
index 6da85698c2d8..524818230e3e 100644
--- a/include/o3tl/optional.hxx
+++ b/include/o3tl/optional.hxx
@@ -25,7 +25,7 @@ namespace o3tl
 using boost::make_optional;
 using boost::optional;
 
-inline constexpr auto nullopt = boost::none;
+inline auto const nullopt = boost::none;
 }
 
 #else
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

[Libreoffice-commits] core.git: include/o3tl sw/source

2019-11-26 Thread Noel Grandin (via logerrit)
 include/o3tl/sorted_vector.hxx |   10 +
 sw/source/core/access/acctable.cxx |   74 +
 2 files changed, 12 insertions(+), 72 deletions(-)

New commits:
commit 4edf078a77167d0fb5201f857146d95a901a809e
Author: Noel Grandin 
AuthorDate: Mon Nov 25 15:41:57 2019 +0200
Commit: Noel Grandin 
CommitDate: Wed Nov 27 06:39:02 2019 +0100

tdf#108642 simplify comparison data calculation

Complex table-based writer doc with sidebar slow to open.

We are only using the extent data in SwAccessibleTableData_Impl as a
comparison method to see if that table structure has changed.
So just compare the rows and columns arrays instead of calculating
extents.
The downside is that we might fire events a little more often.

This takes the opening time from 17s to 10s for me.

Change-Id: I936cbc01072345d6360c0ec162de20b3111a588e
Reviewed-on: https://gerrit.libreoffice.org/83682
Tested-by: Jenkins
Reviewed-by: Noel Grandin 

diff --git a/include/o3tl/sorted_vector.hxx b/include/o3tl/sorted_vector.hxx
index 102287d52a21..088f5a2aa214 100644
--- a/include/o3tl/sorted_vector.hxx
+++ b/include/o3tl/sorted_vector.hxx
@@ -198,6 +198,16 @@ public:
 return (ret.second) ? ret.first : m_vector.end();
 }
 
+bool operator==(const sorted_vector & other) const
+{
+return m_vector == other.m_vector;
+}
+
+bool operator!=(const sorted_vector & other) const
+{
+return m_vector != other.m_vector;
+}
+
 void insert(sorted_vector const& rOther)
 {
// optimization for the rather common case that we are overwriting this 
with the contents
diff --git a/sw/source/core/access/acctable.cxx 
b/sw/source/core/access/acctable.cxx
index 426d448327f3..3de840d534ff 100644
--- a/sw/source/core/access/acctable.cxx
+++ b/sw/source/core/access/acctable.cxx
@@ -77,14 +77,12 @@ class SwAccessibleTableData_Impl
 SwAccessibleMap& mrAccMap;
 Int32Set_Impl   maRows;
 Int32Set_Impl   maColumns;
-std::vector < Int32Pair_Impl > maExtents; // cell extends for event 
processing only
 Point   maTabFramePos;
 const SwTabFrame *mpTabFrame;
 bool const mbIsInPagePreview;
 bool const mbOnlyTableColumnHeader;
 
 void CollectData( const SwFrame *pFrame );
-void CollectExtents( const SwFrame *pFrame );
 
 bool FindCell( const Point& rPos, const SwFrame *pFrame ,
bool bExact, const SwFrame *& rFrame ) const;
@@ -130,11 +128,6 @@ public:
 void CheckRowAndCol( sal_Int32 nRow, sal_Int32 nCol,
  SwAccessibleTable *pThis ) const;
 
-void GetRowColumnAndExtent( const SwRect& rBox,
-  sal_Int32& rRow, sal_Int32& rColumn,
-  sal_Int32& rRowExtent,
-  sal_Int32& rColumnExtent ) const;
-
 const Point& GetTablePos() const { return maTabFramePos; }
 void SetTablePos( const Point& rPos ) { maTabFramePos = rPos; }
 };
@@ -173,42 +166,6 @@ void SwAccessibleTableData_Impl::CollectData( const 
SwFrame *pFrame )
 }
 }
 
-void SwAccessibleTableData_Impl::CollectExtents( const SwFrame *pFrame )
-{
-const SwAccessibleChildSList aList( *pFrame, mrAccMap );
-SwAccessibleChildSList::const_iterator aIter( aList.begin() );
-SwAccessibleChildSList::const_iterator aEndIter( aList.end() );
-while( aIter != aEndIter )
-{
-const SwAccessibleChild& rLower = *aIter;
-const SwFrame *pLower = rLower.GetSwFrame();
-if( pLower )
-{
-if( pLower->IsCellFrame() &&
-rLower.IsAccessible( mbIsInPagePreview ) )
-{
-sal_Int32 nRow, nCol;
-Int32Pair_Impl aCellExtents;
-GetRowColumnAndExtent( pLower->getFrameArea(), nRow, nCol,
-   aCellExtents.first,
-   aCellExtents.second );
-
-maExtents.push_back( aCellExtents );
-}
-else
-{
-// #i77106#
-if ( !pLower->IsRowFrame() ||
- IncludeRow( *pLower ) )
-{
-CollectExtents( pLower );
-}
-}
-}
-++aIter;
-}
-}
-
 bool SwAccessibleTableData_Impl::FindCell(
 const Point& rPos, const SwFrame *pFrame, bool bExact,
 const SwFrame *& rRet ) const
@@ -396,10 +353,8 @@ inline sal_Int32 
SwAccessibleTableData_Impl::GetColumnCount() const
 bool SwAccessibleTableData_Impl::CompareExtents(
 const SwAccessibleTableData_Impl& rCmp ) const
 {
-if( maExtents.size() != rCmp.maExtents.size() )
-return false;
-
-return std::equal(maExtents.begin(), maExtents.end(), 
rCmp.maExtents.begin());
+return maRows == rCmp.maRows
+&& maColumns == 

[Libreoffice-commits] core.git: include/o3tl

2019-11-25 Thread Stephan Bergmann (via logerrit)
 include/o3tl/enumarray.hxx |   24 ++--
 1 file changed, 10 insertions(+), 14 deletions(-)

New commits:
commit af2ed6d5c9bf5495d7aa1036d35a86444a95d35a
Author: Stephan Bergmann 
AuthorDate: Mon Nov 25 17:05:45 2019 +0100
Commit: Stephan Bergmann 
CommitDate: Tue Nov 26 08:39:10 2019 +0100

Remove bogus enumarray[_const]_iterator assignment ops

...that write into the m_buf of reference type (or at least would try to if 
the
assignment op were ever instantiated for enumarray_const_iterator).  They 
have
been present since a0032a2dc2e4ac7615baaacdde5fefa64048822e "improve
o3tl::enumarray const-ness" turned m_buf from a pointer to a reference.  
(Found
with recent Clang 10 trunk -Werror,-Wdeprecated-copy, cf.
 "Remove some redundantly
user-declared copy ctors and assignment ops".)

But then at least some MSVC 2017 would still want to implicitly define them 
as
non-deleted (see  
trying
to build a prior version of this change) and fail, so change m_buf from
reference to pointer.

Change-Id: I3d4a420d2c4c6a6e966df74cfa33b5e00e0af5f6
Reviewed-on: https://gerrit.libreoffice.org/83701
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/o3tl/enumarray.hxx b/include/o3tl/enumarray.hxx
index ca012e197f27..a3c09d56bea0 100644
--- a/include/o3tl/enumarray.hxx
+++ b/include/o3tl/enumarray.hxx
@@ -85,7 +85,7 @@ public:
 
 template
 class enumarray_iterator {
-EA& m_buf;
+EA* m_buf;
 size_t  m_pos;
 public:
 typedef enumarray_iterator  self_type;
@@ -100,19 +100,17 @@ public:
 typedef typename EA::value_type&   reference;
 
 enumarray_iterator(EA& b, size_t start_pos)
- : m_buf(b), m_pos(start_pos) {}
-value_type& operator*()  const { return 
m_buf[static_cast(m_pos)]; }
+ : m_buf(), m_pos(start_pos) {}
+value_type& operator*()  const { return 
(*m_buf)[static_cast(m_pos)]; }
 value_type* operator->() const { return &(operator*()); }
 self_type&  operator++() { ++m_pos; return *this; }
-booloperator!=(self_type const & other) const { return _buf != 
_buf || m_pos != other.m_pos; }
-booloperator==(self_type const & other) const { return _buf == 
_buf && m_pos == other.m_pos; }
-enumarray_iterator&
-operator=(self_type const & other) { m_buf = other.m_buf; 
m_pos = other.m_pos; return *this; }
+booloperator!=(self_type const & other) const { return m_buf != 
other.m_buf || m_pos != other.m_pos; }
+booloperator==(self_type const & other) const { return m_buf == 
other.m_buf && m_pos == other.m_pos; }
 };
 
 template
 class enumarray_const_iterator {
-EA const &  m_buf;
+EA const *  m_buf;
 size_t  m_pos;
 public:
 typedef enumarray_const_iteratorself_type;
@@ -127,14 +125,12 @@ public:
 typedef typename EA::value_type const & reference;
 
 enumarray_const_iterator(EA const & b, size_t start_pos)
- : m_buf(b), m_pos(start_pos) {}
-value_type& operator*()  const { return 
m_buf[static_cast(m_pos)]; }
+ : m_buf(), m_pos(start_pos) {}
+value_type& operator*()  const { return 
(*m_buf)[static_cast(m_pos)]; }
 value_type* operator->() const { return &(operator*()); }
 self_type&  operator++() { ++m_pos; return *this; }
-booloperator!=(self_type const & other) const { return _buf != 
_buf || m_pos != other.m_pos; }
-booloperator==(self_type const & other) const { return _buf == 
_buf && m_pos == other.m_pos; }
-enumarray_const_iterator&
-operator=(self_type const & other) { m_buf = other.m_buf; 
m_pos = other.m_pos; return *this; }
+booloperator!=(self_type const & other) const { return m_buf != 
other.m_buf || m_pos != other.m_pos; }
+booloperator==(self_type const & other) const { return m_buf == 
other.m_buf && m_pos == other.m_pos; }
 };
 
 }; // namespace o3tl
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

[Libreoffice-commits] core.git: include/o3tl

2019-08-23 Thread Noel Grandin (via logerrit)
 include/o3tl/lru_map.hxx |6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

New commits:
commit b8f42b202f7afc882b77b66c4b24c086950f10fc
Author: Noel Grandin 
AuthorDate: Fri Aug 23 09:46:53 2019 +0200
Commit: Noel Grandin 
CommitDate: Fri Aug 23 11:08:24 2019 +0200

loplugin:returnconstval in o3tl

Change-Id: Ib36382243552cd80dab431741f45dc767beccf59
Reviewed-on: https://gerrit.libreoffice.org/77993
Tested-by: Jenkins
Reviewed-by: Noel Grandin 

diff --git a/include/o3tl/lru_map.hxx b/include/o3tl/lru_map.hxx
index 54378a319ece..e822fde0294c 100644
--- a/include/o3tl/lru_map.hxx
+++ b/include/o3tl/lru_map.hxx
@@ -122,7 +122,7 @@ public:
 }
 }
 
-const list_const_iterator_t find(const Key& key)
+list_const_iterator_t find(const Key& key)
 {
 const map_iterator_t i = mLruMap.find(key);
 if (i == mLruMap.cend()) // can't find entry for the key
@@ -155,12 +155,12 @@ public:
 }
 }
 
-const list_const_iterator_t begin() const
+list_const_iterator_t begin() const
 {
 return mLruList.cbegin();
 }
 
-const list_const_iterator_t end() const
+list_const_iterator_t end() const
 {
 return mLruList.cend();
 }
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

[Libreoffice-commits] core.git: include/o3tl

2019-06-03 Thread Noel Grandin (via logerrit)
 include/o3tl/lru_map.hxx |8 
 1 file changed, 8 insertions(+)

New commits:
commit c27e92b29efe573e2cda9844e9ca38965f502443
Author: Noel Grandin 
AuthorDate: Mon Jun 3 16:07:40 2019 +0200
Commit: Noel Grandin 
CommitDate: Mon Jun 3 19:19:08 2019 +0200

fix crash in lru_map/SalBitmap on shutdown

When we shut down, we destroy the various caches, in the process of
which SalBitmap calls back into it's owning cache, causing a SIGSEGV.

Found while loading files from tdf#83426

Change-Id: I53db1621a0fdb75a8e66582662b0e2666499192b
Reviewed-on: https://gerrit.libreoffice.org/73387
Tested-by: Jenkins
Reviewed-by: Noel Grandin 

diff --git a/include/o3tl/lru_map.hxx b/include/o3tl/lru_map.hxx
index 003da59551b5..54378a319ece 100644
--- a/include/o3tl/lru_map.hxx
+++ b/include/o3tl/lru_map.hxx
@@ -69,6 +69,14 @@ public:
 lru_map(size_t nMaxSize)
 : mMaxSize(nMaxSize ? nMaxSize : std::min(mLruMap.max_size(), 
mLruList.max_size()))
 {}
+~lru_map()
+{
+// Some code .e.g. SalBitmap likes to remove itself from a cache 
during it's destructor, which means we
+// get calls into lru_map while we are in destruction, so use the 
swap-and-clear idiom to avoid those problems.
+mLruMap.clear();
+list_t aLruListTemp;
+aLruListTemp.swap(mLruList);
+}
 
 void insert(key_value_pair_t& rPair)
 {
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

[Libreoffice-commits] core.git: include/o3tl include/vcl

2019-05-09 Thread Luboš Luňák (via logerrit)
 include/o3tl/temporary.hxx  |5 +
 include/vcl/uitest/eventdescription.hxx |5 +
 include/vcl/uitest/factory.hxx  |5 +
 include/vcl/uitest/logger.hxx   |5 +
 include/vcl/uitest/uitest.hxx   |5 +
 5 files changed, 25 insertions(+)

New commits:
commit b4946d58eb07aac674574da466829ab19c126c69
Author: Luboš Luňák 
AuthorDate: Wed May 8 16:33:26 2019 +0200
Commit: Luboš Luňák 
CommitDate: Thu May 9 11:10:31 2019 +0200

add missing include guards

Change-Id: I337c0f567112f95e2a1d762e511d5b632dd2892f
Reviewed-on: https://gerrit.libreoffice.org/71997
Tested-by: Jenkins
Reviewed-by: Luboš Luňák 

diff --git a/include/o3tl/temporary.hxx b/include/o3tl/temporary.hxx
index 476e934cb44a..7b6c9a1f9fc7 100644
--- a/include/o3tl/temporary.hxx
+++ b/include/o3tl/temporary.hxx
@@ -7,6 +7,9 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  */
 
+#ifndef INCLUDED_O3TL_TEMPORARY_HXX
+#define INCLUDED_O3TL_TEMPORARY_HXX
+
 #include 
 
 namespace o3tl
@@ -19,4 +22,6 @@ template  constexpr T& temporary(T&& x) { return 
x; }
 template  constexpr T& temporary(T&) = delete;
 }
 
+#endif /* INCLUDED_O3TL_TEMPORARY_HXX */
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/include/vcl/uitest/eventdescription.hxx 
b/include/vcl/uitest/eventdescription.hxx
index ed2b54f3439b..47bf9e117ef9 100644
--- a/include/vcl/uitest/eventdescription.hxx
+++ b/include/vcl/uitest/eventdescription.hxx
@@ -7,6 +7,9 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  */
 
+#ifndef INCLUDED_VCL_UITEST_EVENTDESCRIPTION_HXX
+#define INCLUDED_VCL_UITEST_EVENTDESCRIPTION_HXX
+
 #include 
 #include 
 
@@ -16,4 +19,6 @@ struct EventDescription
 std::map aParameters;
 };
 
+#endif
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/vcl/uitest/factory.hxx b/include/vcl/uitest/factory.hxx
index da645f309b79..3319c5e18583 100644
--- a/include/vcl/uitest/factory.hxx
+++ b/include/vcl/uitest/factory.hxx
@@ -7,6 +7,9 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  */
 
+#ifndef INCLUDED_VCL_UITEST_FACTORY_HXX
+#define INCLUDED_VCL_UITEST_FACTORY_HXX
+
 #include 
 #include 
 
@@ -20,4 +23,6 @@ class UIObject;
 
 typedef std::function(vcl::Window*)> FactoryFunction;
 
+#endif
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/vcl/uitest/logger.hxx b/include/vcl/uitest/logger.hxx
index 89f7c72f693b..f707049040fe 100644
--- a/include/vcl/uitest/logger.hxx
+++ b/include/vcl/uitest/logger.hxx
@@ -7,6 +7,9 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  */
 
+#ifndef INCLUDED_VCL_UITEST_LOGGER_HXX
+#define INCLUDED_VCL_UITEST_LOGGER_HXX
+
 #include 
 
 #include 
@@ -47,4 +50,6 @@ public:
 
 };
 
+#endif
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/vcl/uitest/uitest.hxx b/include/vcl/uitest/uitest.hxx
index 00465b0ee1e8..14356b5b7487 100644
--- a/include/vcl/uitest/uitest.hxx
+++ b/include/vcl/uitest/uitest.hxx
@@ -7,6 +7,9 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  */
 
+#ifndef INCLUDED_VCL_UITEST_UITEST_HXX
+#define INCLUDED_VCL_UITEST_UITEST_HXX
+
 #include 
 
 #include 
@@ -36,4 +39,6 @@ public:
 static std::unique_ptr getFloatWindow();
 };
 
+#endif
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

[Libreoffice-commits] core.git: include/o3tl

2019-03-18 Thread Libreoffice Gerrit user
 include/o3tl/span.hxx |6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

New commits:
commit 6ef8420fdbf8dff16de13147c5ab833bc5e01121
Author: Stephan Bergmann 
AuthorDate: Mon Mar 18 16:26:04 2019 +0100
Commit: Stephan Bergmann 
CommitDate: Mon Mar 18 19:18:17 2019 +0100

Adapt o3tl::span to updated C++2a std::span

...where index_type has changed from ptrdiff_t to size_t, see 
"P1227R2 Signed ssize() functions, unsigned size() functions".  Ideally,
ece27693ba52417bc4b68045f5544a5cc43299dc "Adapt to C++2a 
std::span<>::index_type
being unsigned size_t" could be simplified now to use std::size_t, but 
there may
be build environments that include a C++2a  that hasn't been adapted 
to
P1227R2 yet.

Change-Id: I7bfc0da65d415ef06e94d95b5f62030aeb8b35f6
Reviewed-on: https://gerrit.libreoffice.org/69391
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/o3tl/span.hxx b/include/o3tl/span.hxx
index acb31bab728d..1618b86df897 100644
--- a/include/o3tl/span.hxx
+++ b/include/o3tl/span.hxx
@@ -40,7 +40,7 @@ public:
 using iterator = pointer;
 using const_reverse_iterator = std::reverse_iterator;
 using reverse_iterator = std::reverse_iterator;
-using index_type = std::ptrdiff_t;
+using index_type = std::size_t;
 using difference_type = std::ptrdiff_t;
 
 constexpr span() noexcept : data_(nullptr), size_(0) {}
@@ -52,7 +52,7 @@ public:
 : data_(a), size_(len)
 {
 // not terribly sure about this, might need to strengthen it
-assert((a == nullptr && len == 0) || (a != nullptr && len >= 0));
+assert(a != nullptr || len == 0);
 }
 
 constexpr bool empty() const noexcept { return size_ == 0; }
@@ -75,7 +75,7 @@ public:
 constexpr index_type size() const noexcept { return size_; }
 
 constexpr reference operator [](index_type pos) const {
-assert(0 <= pos && pos < size());
+assert(pos < size());
 return data_[pos];
 }
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

[Libreoffice-commits] core.git: include/o3tl sc/inc sc/source xmlsecurity/qa

2019-03-05 Thread Libreoffice Gerrit user
 include/o3tl/typed_flags_set.hxx|  109 ++--
 include/o3tl/underlyingenumvalue.hxx|   28 
 sc/inc/address.hxx  |5 -
 sc/source/core/tool/address.cxx |4 -
 sc/source/core/tool/reffind.cxx |6 +
 xmlsecurity/qa/unit/signing/signing.cxx |   45 -
 6 files changed, 103 insertions(+), 94 deletions(-)

New commits:
commit b612cf0e06de231b7f936269db3b51a7f0e8ae3b
Author: Stephan Bergmann 
AuthorDate: Tue Mar 5 15:41:18 2019 +0100
Commit: Stephan Bergmann 
CommitDate: Tue Mar 5 22:11:48 2019 +0100

Introduce o3tl::underlyingEnumValue

Change-Id: I6554eb86326159b0da707539f45c411f61c0f3de
Reviewed-on: https://gerrit.libreoffice.org/68761
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/o3tl/typed_flags_set.hxx b/include/o3tl/typed_flags_set.hxx
index 188258febc58..bf795908bad5 100644
--- a/include/o3tl/typed_flags_set.hxx
+++ b/include/o3tl/typed_flags_set.hxx
@@ -25,6 +25,7 @@
 #include 
 #include 
 
+#include 
 #include 
 
 namespace o3tl {
@@ -104,10 +105,10 @@ template
 constexpr typename o3tl::typed_flags::Wrap operator ~(E rhs) {
 assert(
 o3tl::detail::isNonNegative(
-static_cast::type>(rhs)));
+o3tl::underlyingEnumValue(rhs)));
 return static_cast::Wrap>(
 o3tl::typed_flags::mask
-& ~static_cast::type>(rhs));
+& ~o3tl::underlyingEnumValue(rhs));
 }
 
 template constexpr typename o3tl::typed_flags::Wrap operator ~(
@@ -115,7 +116,7 @@ template constexpr typename 
o3tl::typed_flags::Wrap operator ~(
 {
 return static_cast::Wrap>(
 o3tl::typed_flags::mask
-& ~static_cast::type>(rhs));
+& ~o3tl::underlyingEnumValue(rhs));
 }
 
 template constexpr typename o3tl::typed_flags::Wrap operator ^(
@@ -123,13 +124,13 @@ template constexpr typename 
o3tl::typed_flags::Wrap operator ^(
 {
 assert(
 o3tl::detail::isNonNegative(
-static_cast::type>(lhs)));
+o3tl::underlyingEnumValue(lhs)));
 assert(
 o3tl::detail::isNonNegative(
-static_cast::type>(rhs)));
+o3tl::underlyingEnumValue(rhs)));
 return static_cast::Wrap>(
-static_cast::type>(lhs)
-^ static_cast::type>(rhs));
+o3tl::underlyingEnumValue(lhs)
+^ o3tl::underlyingEnumValue(rhs));
 }
 
 template constexpr typename o3tl::typed_flags::Wrap operator ^(
@@ -137,10 +138,10 @@ template constexpr typename 
o3tl::typed_flags::Wrap operator ^(
 {
 assert(
 o3tl::detail::isNonNegative(
-static_cast::type>(lhs)));
+o3tl::underlyingEnumValue(lhs)));
 return static_cast::Wrap>(
-static_cast::type>(lhs)
-^ static_cast::type>(rhs));
+o3tl::underlyingEnumValue(lhs)
+^ o3tl::underlyingEnumValue(rhs));
 }
 
 template constexpr typename o3tl::typed_flags::Wrap operator ^(
@@ -148,10 +149,10 @@ template constexpr typename 
o3tl::typed_flags::Wrap operator ^(
 {
 assert(
 o3tl::detail::isNonNegative(
-static_cast::type>(rhs)));
+o3tl::underlyingEnumValue(rhs)));
 return static_cast::Wrap>(
-static_cast::type>(lhs)
-^ static_cast::type>(rhs));
+o3tl::underlyingEnumValue(lhs)
+^ o3tl::underlyingEnumValue(rhs));
 }
 
 template constexpr
@@ -159,25 +160,21 @@ typename o3tl::typed_flags::Wrap operator ^(
 W lhs, W rhs)
 {
 return static_cast(
-static_cast<
-typename std::underlying_type::type>(
-lhs)
-^ static_cast<
-typename std::underlying_type::type>(
-rhs));
+o3tl::underlyingEnumValue(lhs)
+^ o3tl::underlyingEnumValue(rhs));
 }
 
 template
 constexpr typename o3tl::typed_flags::Wrap operator &(E lhs, E rhs) {
 assert(
 o3tl::detail::isNonNegative(
-static_cast::type>(lhs)));
+o3tl::underlyingEnumValue(lhs)));
 assert(
 o3tl::detail::isNonNegative(
-static_cast::type>(rhs)));
+o3tl::underlyingEnumValue(rhs)));
 return static_cast::Wrap>(
-static_cast::type>(lhs)
-& static_cast::type>(rhs));
+o3tl::underlyingEnumValue(lhs)
+& o3tl::underlyingEnumValue(rhs));
 }
 
 template constexpr typename o3tl::typed_flags::Wrap operator &(
@@ -185,10 +182,10 @@ template constexpr typename 
o3tl::typed_flags::Wrap operator &(
 {
 assert(
 o3tl::detail::isNonNegative(
-static_cast::type>(lhs)));
+o3tl::underlyingEnumValue(lhs)));
 return static_cast::Wrap>(
-static_cast::type>(lhs)
-& static_cast::type>(rhs));
+o3tl::underlyingEnumValue(lhs)
+& o3tl::underlyingEnumValue(rhs));
 }
 
 template constexpr typename o3tl::typed_flags::Wrap operator &(
@@ -196,10 +193,10 @@ template constexpr typename 
o3tl::typed_flags::Wrap operator &(
 {
 

[Libreoffice-commits] core.git: include/o3tl solenv/clang-format

2019-02-25 Thread Libreoffice Gerrit user
 include/o3tl/make_unique.hxx  |   51 --
 solenv/clang-format/blacklist |1 
 2 files changed, 52 deletions(-)

New commits:
commit 97d68765d24c1a9e0715063b4f9c65585281a869
Author: Gabor Kelemen 
AuthorDate: Sat Feb 23 12:23:34 2019 +0100
Commit: Noel Grandin 
CommitDate: Mon Feb 25 17:24:20 2019 +0100

Drop include/o3tl/make_unique.hxx

In favor of std::make_unique

Change-Id: I0428076a10fb7b61c5add994c9970661b375b82c
Reviewed-on: https://gerrit.libreoffice.org/68254
Tested-by: Jenkins
Reviewed-by: Julien Nabet 
Reviewed-by: Noel Grandin 

diff --git a/include/o3tl/make_unique.hxx b/include/o3tl/make_unique.hxx
deleted file mode 100644
index 555e9ca538b8..
--- a/include/o3tl/make_unique.hxx
+++ /dev/null
@@ -1,51 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- */
-
-#ifndef INCLUDED_O3TL_MAKE_UNIQUE_HXX
-#define INCLUDED_O3TL_MAKE_UNIQUE_HXX
-
-#include 
-#include 
-#include 
-
-namespace o3tl
-{
-
-/**
- * Constructs an object of type T and wraps it in a std::unique_ptr.
- *
- * Can be replaced by std::make_unique when we allow C++14.
- */
-template
-typename std::enable_if::value, std::unique_ptr>::type
-make_unique(Args&& ... args)
-{
-return std::unique_ptr(new T(std::forward(args)...));
-}
-
-/**
- * for arrays
- */
-template 
-typename std::enable_if
-<
-std::is_array::value,
-std::unique_ptr
->::type
-make_unique(std::size_t n)
-{
-typedef typename std::remove_extent::type RT;
-return std::unique_ptr(new RT[n]);
-}
-
-}
-
-#endif
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/solenv/clang-format/blacklist b/solenv/clang-format/blacklist
index 457743df6603..39c02006623c 100644
--- a/solenv/clang-format/blacklist
+++ b/solenv/clang-format/blacklist
@@ -6501,7 +6501,6 @@ include/o3tl/functional.hxx
 include/o3tl/lazy_update.hxx
 include/o3tl/lru_map.hxx
 include/o3tl/make_shared.hxx
-include/o3tl/make_unique.hxx
 include/o3tl/numeric.hxx
 include/o3tl/runtimetooustring.hxx
 include/o3tl/safeint.hxx
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

[Libreoffice-commits] core.git: include/o3tl sw/source

2019-02-01 Thread Libreoffice Gerrit user
 include/o3tl/unreachable.hxx |   39 +++
 sw/source/core/fields/reffld.cxx |   17 +++--
 2 files changed, 46 insertions(+), 10 deletions(-)

New commits:
commit 9935a83143c1d994986035ed89e7c94d1fcb2f4d
Author: Stephan Bergmann 
AuthorDate: Thu Jan 31 17:17:34 2019 +0100
Commit: Stephan Bergmann 
CommitDate: Fri Feb 1 11:58:47 2019 +0100

Introduce O3TL_UNREACHABLE as a better alternative to assert(false)

The code in sw/source/core/fields/reffld.cxx had turned into whack-a-mole:  
MSVC
needed the unreachable default:assert(false); to fall through to init some 
vars
to avoid C4701 ("potentially uninitialized local variable").  But Clang 
(with
!NDEBUG, and an implementation of assert marked as noreturn) reported that 
as
"fallthrough annotation in unreachable code", requiring the #ifdef NDEBUG 
guards
to be added.  And now clang-cl (also with !NDEBUG, but with the MSVC
implementation of assert apparently not marked as noreturn) complained about
"unannotated fall-through between switch labels", which wold require the 
#ifdef
NDEBUG guards to be removed again.

O3TL_UNREACHABLE (inspired by LLVM's llvm_unreachable and underyling
LLVM_BUILTIN_UNREACHABLE) hopefully improves on that for all compilers 
involved.
For non-MSVC (i.e., Clang or GCC) it assumes that __builtin_unreachable is
supported (which it is at least for GCC 7, which is our current baseline per
README.md).

Change-Id: I4474f95664d97c3d0e506bab90f80d5ab252ec6e
Reviewed-on: https://gerrit.libreoffice.org/67232
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/o3tl/unreachable.hxx b/include/o3tl/unreachable.hxx
new file mode 100644
index ..bc33d34b534e
--- /dev/null
+++ b/include/o3tl/unreachable.hxx
@@ -0,0 +1,39 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; 
fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INCLUDED_O3TL_UNREACHABLE_HXX
+#define INCLUDED_O3TL_UNREACHABLE_HXX
+
+#include 
+
+#include 
+
+// A better replacement for assert(false) to indicate a place in the code that 
should not be
+// reachable.  This should improve on the sometimes poor false-positive 
warnings emitted by
+// compilers when they cannot detect that some condition flagged by 
assert(false) cannot occur,
+// either because assert is reduced to a no-op by NDEBUG or because assert is 
not marked as noreturn
+// in the MSVC headers.  This is inspired by LLVM's LLVM_BUILTIN_UNREACHABLE
+// (llvm/include/llvm/Support/Compiler.h).
+
+#if defined _MSC_VER
+#define O3TL_UNREACHABLE_detail __assume(false)
+#else // assuming Clang or GCC with support for:
+#define O3TL_UNREACHABLE_detail __builtin_unreachable()
+#endif
+
+#define O3TL_UNREACHABLE   
\
+do 
\
+{  
\
+assert(false); 
\
+O3TL_UNREACHABLE_detail;   
\
+} while (false)
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/sw/source/core/fields/reffld.cxx b/sw/source/core/fields/reffld.cxx
index 6c015e101783..222feb56728e 100644
--- a/sw/source/core/fields/reffld.cxx
+++ b/sw/source/core/fields/reffld.cxx
@@ -19,6 +19,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -557,16 +558,14 @@ void SwGetRefField::UpdateField( const SwTextField* 
pFieldTextAttr )
 nEnd = std::min(nStart + 1, nLen);
 break;
 
-default:
-assert(false); // fall through to appease MSVC C4701
-#ifdef NDEBUG
-[[fallthrough]];
-#endif
 // "Reference" (whole Text)
 case REF_CONTENT:
 nStart = 0;
 nEnd = nLen;
 break;
+
+default:
+O3TL_UNREACHABLE;
 }
 break;
 
@@ -601,15 +600,13 @@ void SwGetRefField::UpdateField( const SwTextField* 
pFieldTextAttr )
 }
 return;
 
-default:
-assert(false); // fall through to appease MSVC C4701
-#ifdef NDEBUG
-[[fallthrough]];
-#endif
 case REF_SETREFATTR:
 nStart = nNumStart;
 nEnd = 

[Libreoffice-commits] core.git: include/o3tl include/sfx2 o3tl/CppunitTest_o3tl_tests.mk o3tl/qa sd/source sfx2/source solenv/clang-format

2019-01-13 Thread Libreoffice Gerrit user
 include/o3tl/array_view.hxx   |  163 --
 include/o3tl/span.hxx |   95 ++
 include/sfx2/dispatch.hxx |4 
 o3tl/CppunitTest_o3tl_tests.mk|2 
 o3tl/qa/test-array_view.cxx   |   85 ---
 o3tl/qa/test-span.cxx |   65 +++
 sd/source/ui/inc/DrawDocShell.hxx |6 -
 sfx2/source/control/dispatch.cxx  |7 -
 solenv/clang-format/blacklist |4 
 9 files changed, 172 insertions(+), 259 deletions(-)

New commits:
commit 73df1aea4f8a779241c053ab54f616f7b3a6dcb9
Author: Stephan Bergmann 
AuthorDate: Sat Jan 12 15:58:00 2019 +0100
Commit: Stephan Bergmann 
CommitDate: Sun Jan 13 11:27:30 2019 +0100

array_view was changed to span in upcoming C++20

...see 
"span: bounds-safe views for sequences of objects".  o3tl::span is still an
incomplete approximation of std::span; removed those o3tl::array_view 
members
that are not present in std::span (and were not used in the code).

Relies on C++17 __has_include to use standard  where available (e.g., 
in
LLVM 7 libc++).

Change-Id: I82a7e246b61b2456fa6183025d25eec4121ad3c9
Reviewed-on: https://gerrit.libreoffice.org/66215
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/o3tl/array_view.hxx b/include/o3tl/array_view.hxx
deleted file mode 100644
index dd6ca7fa94c0..
--- a/include/o3tl/array_view.hxx
+++ /dev/null
@@ -1,163 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; 
fill-column: 100 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- */
-
-#ifndef INCLUDED_O3TL_ARRAY_VIEW_HXX
-#define INCLUDED_O3TL_ARRAY_VIEW_HXX
-
-#include 
-
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
-#include 
-#include 
-#include 
-
-namespace o3tl {
-
-#if defined _MSC_VER
-#pragma warning(push)
-#pragma warning(disable: 4522) // multiple assignment operators specified
-#endif
-
-/** A barebones approximation of C++17(?) .
-  Haven't bothered with more than single-dimensional arrays.
-*/
-template
-class array_view {
-friend class array_view;
-public:
-using value_type = T;
-using pointer = value_type *;
-using const_pointer = value_type const *;
-using reference = value_type &;
-using const_reference = value_type const &;
-using const_iterator = const_pointer;
-using iterator = pointer;
-using const_reverse_iterator = std::reverse_iterator;
-using reverse_iterator = std::reverse_iterator;
-using size_type = std::size_t;
-using difference_type = std::ptrdiff_t;
-
-static constexpr size_type npos = size_type(-1);
-
-constexpr array_view() noexcept : data_(nullptr), size_(0) {}
-
-template
-constexpr array_view (T ()[N]) noexcept : data_(a), size_(N) {}
-
-constexpr array_view (T *a, size_type len) noexcept
-: data_(a), size_(len)
-{
-// not terribly sure about this, might need to relax it
-assert((a == nullptr && len == 0) || (a != nullptr && len > 0));
-}
-
-/// Allow for assigning array_view to array_view i.e.
-///   array_view a;
-///   array_view b = a;
-template::value > >
-array_view& operator=(array_view::type> const & other)
-{
-data_ = other.data_;
-size_ = other.size_;
-return *this;
-}
-
-constexpr bool empty() const noexcept { return size_ == 0; }
-
-constexpr iterator begin() const noexcept { return data_; }
-constexpr iterator end() const noexcept { return begin() + size(); }
-
-constexpr const_iterator cbegin() const noexcept { return begin(); }
-constexpr const_iterator cend() const noexcept { return end(); }
-
-reverse_iterator rbegin() const noexcept
-{ return reverse_iterator(end()); }
-reverse_iterator rend() const noexcept
-{ return reverse_iterator(begin()); }
-
-constexpr const_reverse_iterator crbegin() const noexcept
-{ return rbegin(); }
-constexpr const_reverse_iterator crend() const noexcept { return rend(); }
-
-constexpr size_type size() const noexcept { return size_; }
-constexpr size_type length() const noexcept { return size(); }
-
-constexpr size_type max_size() const noexcept {
-(void) this; // silence loplugin:staticmethods
-return npos - 1;
-}
-
-constexpr reference operator [](size_type pos) const {
-assert(pos < size());
-return data_[pos];
-}
-
-constexpr reference at(size_type pos) const {
-if (pos >= size()) {
-throw std::out_of_range("o3tl::array_view::at");
-}
- 

[Libreoffice-commits] core.git: include/o3tl o3tl/qa

2018-12-16 Thread Libreoffice Gerrit user
 include/o3tl/string_view.hxx |   11 +--
 o3tl/qa/test-string_view.cxx |9 +
 2 files changed, 14 insertions(+), 6 deletions(-)

New commits:
commit 0d2ac93f4a3bec9d2fe2719b270333193d20596b
Author: Stephan Bergmann 
AuthorDate: Sun Dec 16 12:52:56 2018 +0100
Commit: Stephan Bergmann 
CommitDate: Sun Dec 16 17:14:33 2018 +0100

Fix o3tl::string_view streaming operator <<

(The unnecessary os.setstate(std::ios_base::failbit) was due to a 
misreading of
C++17 [ostream.formatted.reqmts]/1.)

Change-Id: I7d8285230cb316c7af45c76029e9629517d05d56
Reviewed-on: https://gerrit.libreoffice.org/65217
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/o3tl/string_view.hxx b/include/o3tl/string_view.hxx
index b605da65ac90..2bc182034342 100644
--- a/include/o3tl/string_view.hxx
+++ b/include/o3tl/string_view.hxx
@@ -732,12 +732,13 @@ operator <<(
 std::basic_ostream & os,
 basic_string_view str)
 {
-typename std::basic_ostream::sentry sentry;
+typename std::basic_ostream::sentry sentry(os);
 if (sentry) {
 auto const w = os.width();
-auto const pad
-= std::max::type>(
-w < 0 ? 0 : w, str.size());
+auto pad
+= std::max::type>(
+  w < 0 ? 0 : w, str.size())
+  - str.size();
 auto const after = (os.flags() & std::ios_base::adjustfield)
 == std::ios_base::left;
 if (pad != 0 && !after) {
@@ -754,8 +755,6 @@ operator <<(
 }
 }
 os.width(0);
-} else {
-os.setstate(std::ios_base::failbit);
 }
 return os;
 }
diff --git a/o3tl/qa/test-string_view.cxx b/o3tl/qa/test-string_view.cxx
index 977cfebc460a..fb6239fca379 100644
--- a/o3tl/qa/test-string_view.cxx
+++ b/o3tl/qa/test-string_view.cxx
@@ -9,7 +9,9 @@
 
 #include 
 
+#include 
 #include 
+#include 
 
 #include 
 #include 
@@ -27,6 +29,7 @@ private:
 CPPUNIT_TEST(testChar32Literal);
 CPPUNIT_TEST(testWcharLiteral);
 CPPUNIT_TEST(testOperations);
+CPPUNIT_TEST(testOutput);
 CPPUNIT_TEST_SUITE_END();
 
 void testCharLiteral() {
@@ -203,6 +206,12 @@ private:
 v.find_last_not_of("fxo", o3tl::string_view::npos, 2));
 CPPUNIT_ASSERT_EQUAL(npos, v.find_last_not_of("fxo"));
 }
+
+void testOutput() {
+std::ostringstream s;
+s << o3tl::string_view("foo");
+CPPUNIT_ASSERT_EQUAL(std::string("foo"), s.str());
+}
 };
 
 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/o3tl o3tl/qa vcl/inc vcl/source

2018-10-06 Thread Libreoffice Gerrit user
 include/o3tl/lru_map.hxx  |7 ---
 o3tl/qa/test-lru_map.cxx  |   20 
 vcl/inc/impfontcache.hxx  |3 ++-
 vcl/source/font/fontcache.cxx |   40 
 4 files changed, 46 insertions(+), 24 deletions(-)

New commits:
commit 16a338e173083954a9932a3a4005f172309c784e
Author: Jan-Marek Glogowski 
AuthorDate: Fri Oct 5 17:08:49 2018 +0200
Commit: Jan-Marek Glogowski 
CommitDate: Sat Oct 6 16:23:44 2018 +0200

Convert ImplFontCache to use o3tl::lru_map

We still do our own cleanup of the LRU map, as we can't drop
any fonts in use.

Change-Id: I8ec5c6ce8f80893635621357e9085950e7010f5b
Reviewed-on: https://gerrit.libreoffice.org/61455
Tested-by: Jenkins
Reviewed-by: Jan-Marek Glogowski 

diff --git a/include/o3tl/lru_map.hxx b/include/o3tl/lru_map.hxx
index 79e81293a858..003da59551b5 100644
--- a/include/o3tl/lru_map.hxx
+++ b/include/o3tl/lru_map.hxx
@@ -31,7 +31,7 @@ namespace o3tl
  * for most of the operations with a combination unordered map and linked list.
  *
  **/
-template>
+template, class 
KeyEqual = std::equal_to>
 class lru_map final
 {
 public:
@@ -42,7 +42,7 @@ private:
 typedef typename list_t::iterator list_iterator_t;
 typedef typename list_t::const_iterator list_const_iterator_t;
 
-typedef std::unordered_map map_t;
+typedef std::unordered_map map_t;
 typedef typename map_t::iterator map_iterator_t;
 typedef typename map_t::const_iterator map_const_iterator_t;
 
@@ -65,8 +65,9 @@ public:
 typedef list_iterator_t iterator;
 typedef list_const_iterator_t const_iterator;
 
+// a size of 0 effectively disables the LRU cleanup code
 lru_map(size_t nMaxSize)
-: mMaxSize(nMaxSize)
+: mMaxSize(nMaxSize ? nMaxSize : std::min(mLruMap.max_size(), 
mLruList.max_size()))
 {}
 
 void insert(key_value_pair_t& rPair)
diff --git a/o3tl/qa/test-lru_map.cxx b/o3tl/qa/test-lru_map.cxx
index 7a4886d3be3e..a7f9777e2c5f 100644
--- a/o3tl/qa/test-lru_map.cxx
+++ b/o3tl/qa/test-lru_map.cxx
@@ -28,6 +28,7 @@ public:
 void testLruRemoval();
 void testCustomHash();
 void testRemoveIf();
+void testNoAutoCleanup();
 
 CPPUNIT_TEST_SUITE(lru_map_test);
 CPPUNIT_TEST(testBaseUsage);
@@ -36,6 +37,7 @@ public:
 CPPUNIT_TEST(testLruRemoval);
 CPPUNIT_TEST(testCustomHash);
 CPPUNIT_TEST(testRemoveIf);
+CPPUNIT_TEST(testNoAutoCleanup);
 CPPUNIT_TEST_SUITE_END();
 };
 
@@ -289,6 +291,24 @@ void lru_map_test::testRemoveIf()
 CPPUNIT_ASSERT_EQUAL(size_t(0), lru.size());
 }
 
+void lru_map_test::testNoAutoCleanup()
+{
+o3tl::lru_map lru(0);
+CPPUNIT_ASSERT_EQUAL(size_t(0), lru.size());
+lru.insert({0,0});
+lru.insert({1,1});
+CPPUNIT_ASSERT_EQUAL(size_t(2), lru.size());
+lru.insert({0,0});
+CPPUNIT_ASSERT_EQUAL(size_t(2), lru.size());
+
+int i = 0;
+for (auto  : lru)
+{
+CPPUNIT_ASSERT_EQUAL(i, rPair.first);
+++i;
+}
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(lru_map_test);
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/inc/impfontcache.hxx b/vcl/inc/impfontcache.hxx
index c96994300176..ee39883f2199 100644
--- a/vcl/inc/impfontcache.hxx
+++ b/vcl/inc/impfontcache.hxx
@@ -69,7 +69,8 @@ private:
 // cache of recently used font instances
 struct IFSD_Equal { bool operator()( const FontSelectPattern&, const 
FontSelectPattern& ) const; };
 struct IFSD_Hash { size_t operator()( const FontSelectPattern& ) const; };
-typedef std::unordered_map, IFSD_Hash, IFSD_Equal> FontInstanceList;
+typedef o3tl::lru_map, IFSD_Hash, IFSD_Equal> FontInstanceList;
+typedef FontInstanceList::key_value_pair_t FontInstanceListPair;
 
 LogicalFontInstance* mpLastHitCacheEntry; ///< keeps the last hit cache 
entry
 FontInstanceList maFontInstanceList;
diff --git a/vcl/source/font/fontcache.cxx b/vcl/source/font/fontcache.cxx
index 0db997fe510f..2b2e062ecea0 100644
--- a/vcl/source/font/fontcache.cxx
+++ b/vcl/source/font/fontcache.cxx
@@ -85,13 +85,14 @@ bool ImplFontCache::IFSD_Equal::operator()(const 
FontSelectPattern& rA, const Fo
 
 ImplFontCache::ImplFontCache()
 : mpLastHitCacheEntry( nullptr )
+, maFontInstanceList(0)
 // The cache limit is set by the rough number of characters needed to read 
your average Asian newspaper.
 , m_aBoundRectCache(3000)
 {}
 
 ImplFontCache::~ImplFontCache()
 {
-for (auto & rLFI : maFontInstanceList)
+for (const auto & rLFI : maFontInstanceList)
 rLFI.second->mpFontCache = nullptr;
 }
 
@@ -115,7 +116,7 @@ rtl::Reference 
ImplFontCache::GetFontInstance( PhysicalFont
 pFontInstance = mpLastHitCacheEntry;
 else
 {
-FontInstanceList::iterator it = maFontInstanceList.find( aFontSelData 
);
+FontInstanceList::const_iterator it = maFontInstanceList.find( 
aFontSelData );
 if( it != maFontInstanceList.end() )
 

[Libreoffice-commits] core.git: include/o3tl o3tl/qa vcl/inc vcl/source

2018-10-06 Thread Libreoffice Gerrit user
 include/o3tl/lru_map.hxx |   27 ++-
 o3tl/qa/test-lru_map.cxx |   55 +++
 vcl/inc/fontinstance.hxx |6 
 vcl/inc/impfontcache.hxx |   48 +-
 vcl/source/font/fontcache.cxx|   38 ++
 vcl/source/font/fontinstance.cxx |   13 +
 6 files changed, 179 insertions(+), 8 deletions(-)

New commits:
commit 612339e574293b248c44cc04a4fae0c77a64ad53
Author: Jan-Marek Glogowski 
AuthorDate: Thu Oct 4 14:03:07 2018 +0200
Commit: Jan-Marek Glogowski 
CommitDate: Sat Oct 6 15:17:52 2018 +0200

Add a glyph-bound-rect cache to the font cache

This way the font cache can correctly invalidate the cached glyph
rects when a font is dropped from the cache.

Change-Id: I050866099742334f01cac1b872228a017ddb5e9b
Reviewed-on: https://gerrit.libreoffice.org/61371
Tested-by: Jenkins
Reviewed-by: Jan-Marek Glogowski 

diff --git a/include/o3tl/lru_map.hxx b/include/o3tl/lru_map.hxx
index 015120e31cb3..79e81293a858 100644
--- a/include/o3tl/lru_map.hxx
+++ b/include/o3tl/lru_map.hxx
@@ -34,8 +34,10 @@ namespace o3tl
 template>
 class lru_map final
 {
-private:
+public:
 typedef typename std::pair key_value_pair_t;
+
+private:
 typedef std::list list_t;
 typedef typename list_t::iterator list_iterator_t;
 typedef typename list_t::const_iterator list_const_iterator_t;
@@ -58,6 +60,7 @@ private:
 mLruList.pop_back();
 }
 }
+
 public:
 typedef list_iterator_t iterator;
 typedef list_const_iterator_t const_iterator;
@@ -126,6 +129,28 @@ public:
 }
 }
 
+// reverse-iterates the list removing all items matching the predicate
+template
+void remove_if(UnaryPredicate pred)
+{
+auto it = mLruList.rbegin();
+while (it != mLruList.rend())
+{
+if (pred(*it))
+{
+mLruMap.erase(it->first);
+it = decltype(it){ mLruList.erase(std::next(it).base()) };
+}
+else
+++it;
+}
+}
+
+const list_const_iterator_t begin() const
+{
+return mLruList.cbegin();
+}
+
 const list_const_iterator_t end() const
 {
 return mLruList.cend();
diff --git a/o3tl/qa/test-lru_map.cxx b/o3tl/qa/test-lru_map.cxx
index 096b21ec5189..7a4886d3be3e 100644
--- a/o3tl/qa/test-lru_map.cxx
+++ b/o3tl/qa/test-lru_map.cxx
@@ -27,6 +27,7 @@ public:
 void testReplaceValue();
 void testLruRemoval();
 void testCustomHash();
+void testRemoveIf();
 
 CPPUNIT_TEST_SUITE(lru_map_test);
 CPPUNIT_TEST(testBaseUsage);
@@ -34,6 +35,7 @@ public:
 CPPUNIT_TEST(testReplaceValue);
 CPPUNIT_TEST(testLruRemoval);
 CPPUNIT_TEST(testCustomHash);
+CPPUNIT_TEST(testRemoveIf);
 CPPUNIT_TEST_SUITE_END();
 };
 
@@ -234,6 +236,59 @@ void lru_map_test::testCustomHash()
 CPPUNIT_ASSERT_EQUAL(13, lru.find(TestClassKey(2,1))->second);
 }
 
+void lru_map_test::testRemoveIf()
+{
+typedef o3tl::lru_map IntMap;
+typedef IntMap::key_value_pair_t IntMapPair;
+struct limit_except : public std::exception {};
+
+IntMap lru(6);
+int i = 0;
+for (; i < 8; i++)
+lru.insert({i, i});
+CPPUNIT_ASSERT_EQUAL(size_t(6), lru.size());
+// now contains 7..2
+
+// remove everything < 4 from the back
+try
+{
+lru.remove_if([] (IntMapPair const& rPair) {
+if (rPair.first >= 4)
+throw limit_except();
+return true;
+});
+CPPUNIT_ASSERT(false); // not reached
+}
+catch (limit_except)
+{
+// contains 7..4
+CPPUNIT_ASSERT_EQUAL(size_t(4), lru.size());
+}
+
+// remove all even numbers
+lru.remove_if([] (IntMapPair const& rPair) { return (0 == rPair.first % 
2); });
+CPPUNIT_ASSERT_EQUAL(size_t(2), lru.size());
+// contains 7, 5
+
+lru.insert({5, 5});
+// contains 5, 7
+
+i = 5;
+for (auto  : lru)
+{
+CPPUNIT_ASSERT_EQUAL(i, rPair.first);
+i += 2;
+}
+
+// remove the first item
+lru.remove_if([] (IntMapPair const& rPair) { return (rPair.first == 5); });
+CPPUNIT_ASSERT_EQUAL(size_t(1), lru.size());
+
+// remove the only item
+lru.remove_if([] (IntMapPair const& rPair) { return (rPair.first == 7); });
+CPPUNIT_ASSERT_EQUAL(size_t(0), lru.size());
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(lru_map_test);
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/inc/fontinstance.hxx b/vcl/inc/fontinstance.hxx
index 597c747553ac..b3b67c8a9079 100644
--- a/vcl/inc/fontinstance.hxx
+++ b/vcl/inc/fontinstance.hxx
@@ -25,6 +25,9 @@
 
 #include 
 #include 
+#include 
+#include 
+
 #include 
 #include 
 
@@ -67,6 +70,9 @@ public: // TODO: make data members private
 const PhysicalFontFace* GetFontFace() const { return m_pFontFace.get(); }
 

[Libreoffice-commits] core.git: include/o3tl sw/source

2018-10-06 Thread Libreoffice Gerrit user
 include/o3tl/sorted_vector.hxx  |   11 +++
 sw/source/filter/html/htmlfly.hxx   |4 ++--
 sw/source/filter/html/htmlflywriter.cxx |   10 --
 sw/source/filter/html/htmlforw.cxx  |2 +-
 sw/source/filter/html/wrthtml.cxx   |6 +-
 5 files changed, 19 insertions(+), 14 deletions(-)

New commits:
commit bb2ff075642664084e735948fcc65e21ad861937
Author: Noel Grandin 
AuthorDate: Wed Oct 3 14:29:32 2018 +0200
Commit: Noel Grandin 
CommitDate: Sat Oct 6 08:16:24 2018 +0200

loplugin:useuniqueptr in SwHTMLPosFlyFrames

and add a new method erase_extract to o3tl::sorted_vector, otherwise
there is no decent way to extract an element from such a vector without
freeing it.

Change-Id: I769782c04a54a2d7433e8349c99134f997a54689
Reviewed-on: https://gerrit.libreoffice.org/61345
Tested-by: Jenkins
Reviewed-by: Noel Grandin 

diff --git a/include/o3tl/sorted_vector.hxx b/include/o3tl/sorted_vector.hxx
index 6e245353fe70..8324e333198a 100644
--- a/include/o3tl/sorted_vector.hxx
+++ b/include/o3tl/sorted_vector.hxx
@@ -97,6 +97,17 @@ public:
m_vector.begin() + (last - m_vector.begin()));
 }
 
+/**
+ * make erase return the removed element, otherwise there is no useful way 
of extracting a std::unique_ptr
+ * from this.
+ */
+Value erase_extract( size_t index )
+{
+Value val = std::move(m_vector[index]);
+m_vector.erase(m_vector.begin() + index);
+return val;
+}
+
 void clear()
 {
 m_vector.clear();
diff --git a/sw/source/filter/html/htmlfly.hxx 
b/sw/source/filter/html/htmlfly.hxx
index 5873baf28dad..f12ea3b5582b 100644
--- a/sw/source/filter/html/htmlfly.hxx
+++ b/sw/source/filter/html/htmlfly.hxx
@@ -122,8 +122,8 @@ public:
 };
 
 class SwHTMLPosFlyFrames
-: public o3tl::sorted_vector,
+: public o3tl::sorted_vector,
+o3tl::less_uniqueptr_to,
 o3tl::find_partialorder_ptrequals>
 {};
 
diff --git a/sw/source/filter/html/htmlflywriter.cxx 
b/sw/source/filter/html/htmlflywriter.cxx
index 9f4987815024..f4f0da70c2f1 100644
--- a/sw/source/filter/html/htmlflywriter.cxx
+++ b/sw/source/filter/html/htmlflywriter.cxx
@@ -249,7 +249,7 @@ sal_uInt16 SwHTMLWriter::GuessFrameType( const 
SwFrameFormat& rFrameFormat,
 bEmpty = true;
 if( m_pHTMLPosFlyFrames )
 {
-for( auto pHTMLPosFlyFrame : *m_pHTMLPosFlyFrames )
+for( auto & pHTMLPosFlyFrame : *m_pHTMLPosFlyFrames )
 {
 sal_uLong nIdx = 
pHTMLPosFlyFrame->GetNdIndex().GetIndex();
 bEmpty = (nIdx != nStt) && (nIdx != nStt-1);
@@ -348,8 +348,7 @@ void SwHTMLWriter::CollectFlyFrames()
 if( !m_pHTMLPosFlyFrames )
 m_pHTMLPosFlyFrames.reset(new SwHTMLPosFlyFrames);
 
-SwHTMLPosFlyFrame *pNew = new SwHTMLPosFlyFrame(**aIter, pSdrObj, 
nMode);
-m_pHTMLPosFlyFrames->insert( pNew );
+m_pHTMLPosFlyFrames->insert( 
o3tl::make_unique(**aIter, pSdrObj, nMode) );
 }
 }
 
@@ -374,7 +373,7 @@ bool SwHTMLWriter::OutFlyFrame( sal_uLong nNdIdx, sal_Int32 
nContentIdx, HtmlPos
 for( ; !bRestart && i < m_pHTMLPosFlyFrames->size() &&
 (*m_pHTMLPosFlyFrames)[i]->GetNdIndex().GetIndex() == nNdIdx; i++ )
 {
-SwHTMLPosFlyFrame *pPosFly = (*m_pHTMLPosFlyFrames)[i];
+SwHTMLPosFlyFrame *pPosFly = (*m_pHTMLPosFlyFrames)[i].get();
 if( ( HtmlPosition::Any == nPos ||
   pPosFly->GetOutPos() == nPos ) &&
 pPosFly->GetContentIndex() == nContentIdx )
@@ -382,7 +381,7 @@ bool SwHTMLWriter::OutFlyFrame( sal_uLong nNdIdx, sal_Int32 
nContentIdx, HtmlPos
 // It is important to remove it first, because additional
 // elements or the whole array could be deleted on
 // deeper recursion levels.
-m_pHTMLPosFlyFrames->erase(i);
+std::unique_ptr flyHolder = 
m_pHTMLPosFlyFrames->erase_extract(i);
 i--;
 if( m_pHTMLPosFlyFrames->empty() )
 {
@@ -408,7 +407,6 @@ bool SwHTMLWriter::OutFlyFrame( sal_uLong nNdIdx, sal_Int32 
nContentIdx, HtmlPos
 break;
 default: break;
 }
-delete pPosFly;
 }
 else
 {
diff --git a/sw/source/filter/html/htmlforw.cxx 
b/sw/source/filter/html/htmlforw.cxx
index 85db134bf892..b3f2d6088c00 100644
--- a/sw/source/filter/html/htmlforw.cxx
+++ b/sw/source/filter/html/htmlforw.cxx
@@ -1332,7 +1332,7 @@ void SwHTMLWriter::GetControls()
 // collect the paragraph-bound controls
 for( size_t i=0; isize(); i++ )
 {
-const SwHTMLPosFlyFrame* pPosFlyFrame = (*m_pHTMLPosFlyFrames)[ i 
];
+

[Libreoffice-commits] core.git: include/o3tl

2018-10-05 Thread Libreoffice Gerrit user
 include/o3tl/lru_map.hxx |   10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

New commits:
commit e7d5bad5ae083da12c3ec4a4a8bdc8b42447a242
Author: Jan-Marek Glogowski 
AuthorDate: Fri Oct 5 22:02:45 2018 +
Commit: Jan-Marek Glogowski 
CommitDate: Sat Oct 6 02:25:40 2018 +0200

lru_map: fix std::move insert

After the move the std::pair is invalid.
That caused invalid iterators on lookups - hard to debug...
Also adds an assertion to warn if size of map and list differ.

Change-Id: Ib987d47963d5e1009d64a96dcdd588a0bc27cd77
Reviewed-on: https://gerrit.libreoffice.org/61451
Tested-by: Jenkins
Reviewed-by: Jan-Marek Glogowski 

diff --git a/include/o3tl/lru_map.hxx b/include/o3tl/lru_map.hxx
index f2369e45030a..015120e31cb3 100644
--- a/include/o3tl/lru_map.hxx
+++ b/include/o3tl/lru_map.hxx
@@ -11,6 +11,7 @@
 #ifndef INCLUDED_O3TL_LRU_MAP_HXX
 #define INCLUDED_O3TL_LRU_MAP_HXX
 
+#include 
 #include 
 #include 
 
@@ -74,7 +75,8 @@ public:
 // add to front of the list
 mLruList.push_front(rPair);
 // add the list position (iterator) to the map
-mLruMap[rPair.first] = mLruList.begin();
+auto it = mLruList.begin();
+mLruMap[it->first] = it;
 checkLRU();
 }
 else // already exists -> replace value
@@ -95,7 +97,8 @@ public:
 // add to front of the list
 mLruList.push_front(std::move(rPair));
 // add the list position (iterator) to the map
-mLruMap[rPair.first] = mLruList.begin();
+auto it = mLruList.begin();
+mLruMap[it->first] = it;
 checkLRU();
 }
 else // already exists -> replace value
@@ -130,7 +133,8 @@ public:
 
 size_t size() const
 {
-return mLruList.size();
+assert(mLruMap.size() == mLruList.size());
+return mLruMap.size();
 }
 
 void clear()
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/o3tl sw/source

2018-10-04 Thread Libreoffice Gerrit user
 include/o3tl/sorted_vector.hxx   |   20 
 sw/source/core/crsr/crstrvl.cxx  |4 ++--
 sw/source/core/doc/DocumentFieldsManager.cxx |5 ++---
 sw/source/core/doc/doc.cxx   |4 ++--
 sw/source/core/doc/docfld.cxx|   19 ---
 sw/source/core/fields/docufld.cxx|   11 +--
 sw/source/core/fields/fldlst.cxx |8 
 sw/source/core/inc/docfld.hxx|4 +---
 8 files changed, 44 insertions(+), 31 deletions(-)

New commits:
commit 04c5f27e8f904f01b1dbfba2b95ed57a9e439f91
Author: Noel Grandin 
AuthorDate: Wed Oct 3 14:04:28 2018 +0200
Commit: Noel Grandin 
CommitDate: Thu Oct 4 12:46:33 2018 +0200

loplugin:useuniqueptr in SetGetExpFields

and a couple more utility methods to o3tl::sorted_vector to make this
easier

Change-Id: Ie8899b67fffa1ac98ae46b7fa70a7e35f866
Reviewed-on: https://gerrit.libreoffice.org/61344
Tested-by: Jenkins
Reviewed-by: Noel Grandin 

diff --git a/include/o3tl/sorted_vector.hxx b/include/o3tl/sorted_vector.hxx
index 7c95a1ace24e..6e245353fe70 100644
--- a/include/o3tl/sorted_vector.hxx
+++ b/include/o3tl/sorted_vector.hxx
@@ -243,6 +243,26 @@ public:
 tmp.release();
 return ret;
 }
+/**
+ * implement upper_bound for sorted_vectors containing std::unique_ptr
+ */
+typename super_sorted_vector::const_iterator upper_bound( typename 
Value::element_type const * x ) const
+{
+Value tmp(const_cast(x));
+auto ret = super_sorted_vector::upper_bound(tmp);
+tmp.release();
+return ret;
+}
+/**
+ * implement lower_bound for sorted_vectors containing std::unique_ptr
+ */
+typename super_sorted_vector::const_iterator lower_bound( typename 
Value::element_type const * x ) const
+{
+Value tmp(const_cast(x));
+auto ret = super_sorted_vector::lower_bound(tmp);
+tmp.release();
+return ret;
+}
 };
 
 
diff --git a/sw/source/core/crsr/crstrvl.cxx b/sw/source/core/crsr/crstrvl.cxx
index 1cedfc908ec8..b93ab75d4718 100644
--- a/sw/source/core/crsr/crstrvl.cxx
+++ b/sw/source/core/crsr/crstrvl.cxx
@@ -674,9 +674,9 @@ static void lcl_MakeFieldLst(
 if ( pCFrame != nullptr
  && ( bInReadOnly || !pCFrame->IsProtected() ) )
 {
-SetGetExpField* pNew = new SetGetExpField( SwNodeIndex( 
rTextNode ), pTextField );
+std::unique_ptr pNew(new SetGetExpField( 
SwNodeIndex( rTextNode ), pTextField ));
 pNew->SetBodyPos( *pCFrame );
-rLst.insert( pNew );
+rLst.insert( std::move(pNew) );
 }
 }
 }
diff --git a/sw/source/core/doc/DocumentFieldsManager.cxx 
b/sw/source/core/doc/DocumentFieldsManager.cxx
index d1e5f78af255..208b467a41c0 100644
--- a/sw/source/core/doc/DocumentFieldsManager.cxx
+++ b/sw/source/core/doc/DocumentFieldsManager.cxx
@@ -1446,7 +1446,7 @@ void DocumentFieldsManager::FieldsToCalc( SwCalc& rCalc, 
const SetGetExpField& r
 {
 SetGetExpFields::const_iterator const itLast =
 mpUpdateFields->GetSortLst()->upper_bound(
-const_cast());
+);
 for( SetGetExpFields::const_iterator it = 
mpUpdateFields->GetSortLst()->begin(); it != itLast; ++it )
 lcl_CalcField( m_rDoc, rCalc, **it, pMgr );
 }
@@ -1496,8 +1496,7 @@ void DocumentFieldsManager::FieldsToExpand( 
SwHashTable & rHashTable,
 rHashTable.resize(nTableSize);
 
 SetGetExpFields::const_iterator const itLast =
-mpUpdateFields->GetSortLst()->upper_bound(
-const_cast());
+mpUpdateFields->GetSortLst()->upper_bound();
 
 for( SetGetExpFields::const_iterator it = 
mpUpdateFields->GetSortLst()->begin(); it != itLast; ++it )
 {
diff --git a/sw/source/core/doc/doc.cxx b/sw/source/core/doc/doc.cxx
index ed90bf3e2fcb..be3f1947d9b9 100644
--- a/sw/source/core/doc/doc.cxx
+++ b/sw/source/core/doc/doc.cxx
@@ -561,8 +561,8 @@ bool sw_GetPostIts(
 if (pSrtLst)
 {
 SwNodeIndex aIdx( pTextField->GetTextNode() );
-PostItField_* pNew = new PostItField_( aIdx, pTextField );
-pSrtLst->insert( pNew );
+std::unique_ptr pNew(new PostItField_( aIdx, 
pTextField ));
+pSrtLst->insert( std::move(pNew) );
 }
 else
 break;  // we just wanted to check for the existence of 
postits ...
diff --git a/sw/source/core/doc/docfld.cxx b/sw/source/core/doc/docfld.cxx
index 873a69b62cbe..db1d7351e7c3 100644
--- a/sw/source/core/doc/docfld.cxx
+++ b/sw/source/core/doc/docfld.cxx
@@ -791,7 +791,6 @@ void SwDocUpdateField::InsDelFieldInFieldLst( bool bIns, 
const SwTextField& rFie
 for( SetGetExpFields::size_type n = 0; n < 

[Libreoffice-commits] core.git: include/o3tl o3tl/qa

2018-09-19 Thread Libreoffice Gerrit user
 include/o3tl/sorted_vector.hxx |   12 ++
 o3tl/qa/test-sorted_vector.cxx |   48 +
 2 files changed, 60 insertions(+)

New commits:
commit 0bc059f2a893d812e29d6a72d4f988428b5ea346
Author: Noel Grandin 
AuthorDate: Wed Sep 19 08:55:09 2018 +0200
Commit: Noel Grandin 
CommitDate: Wed Sep 19 10:33:28 2018 +0200

implement find(T*) for o3tl::sorted_vector when it contains unique_ptr

and add some unit tests

Change-Id: I9a01c9fa2fbbf3a553663a980ee6e958f9819645
Reviewed-on: https://gerrit.libreoffice.org/60737
Tested-by: Jenkins
Reviewed-by: Noel Grandin 

diff --git a/include/o3tl/sorted_vector.hxx b/include/o3tl/sorted_vector.hxx
index 254d627604df..7c95a1ace24e 100644
--- a/include/o3tl/sorted_vector.hxx
+++ b/include/o3tl/sorted_vector.hxx
@@ -224,6 +224,7 @@ class sorted_vector : public 
sorted_vector::sorted_vector;
+typedef sorted_vector super_sorted_vector;
 
 sorted_vector(sorted_vector const&) = delete;
 sorted_vector& operator=(sorted_vector const&) = delete;
@@ -231,6 +232,17 @@ public:
 sorted_vector() = default;
 sorted_vector(sorted_vector&&) = default;
 sorted_vector& operator=(sorted_vector&&) = default;
+
+/**
+ * implement find for sorted_vectors containing std::unique_ptr
+ */
+typename super_sorted_vector::const_iterator find( typename 
Value::element_type const * x ) const
+{
+Value tmp(const_cast(x));
+auto ret = super_sorted_vector::find(tmp);
+tmp.release();
+return ret;
+}
 };
 
 
diff --git a/o3tl/qa/test-sorted_vector.cxx b/o3tl/qa/test-sorted_vector.cxx
index 3de3f005f6c6..dd622e0cea0d 100644
--- a/o3tl/qa/test-sorted_vector.cxx
+++ b/o3tl/qa/test-sorted_vector.cxx
@@ -12,7 +12,9 @@
 #include 
 #include 
 
+#include 
 #include 
+#include 
 
 using namespace ::o3tl;
 
@@ -250,6 +252,50 @@ public:
 CPPUNIT_ASSERT_EQUAL( static_cast(0), aVec.size() );
 }
 
+void testUniquePtr1()
+{
+o3tl::sorted_vector, 
o3tl::less_uniqueptr_to> aVec;
+
+auto str_c = 
aVec.insert(o3tl::make_unique("c")).first->get();
+auto str_b1 = 
aVec.insert(o3tl::make_unique("b")).first->get();
+CPPUNIT_ASSERT(!aVec.insert(o3tl::make_unique("b")).second);
+aVec.insert(o3tl::make_unique("a"));
+CPPUNIT_ASSERT_EQUAL( static_cast(3), aVec.size() );
+CPPUNIT_ASSERT_EQUAL( OUString("a"), *aVec[0] );
+CPPUNIT_ASSERT_EQUAL( OUString("b"), *aVec[1] );
+CPPUNIT_ASSERT_EQUAL( OUString("c"), *aVec[2] );
+
+CPPUNIT_ASSERT( aVec.find(str_c) != aVec.end() );
+CPPUNIT_ASSERT( aVec.find(str_b1) != aVec.end() );
+
+OUString tmp("b");
+CPPUNIT_ASSERT( aVec.find() != aVec.end() );
+OUString tmp2("z");
+CPPUNIT_ASSERT( bool(aVec.find() == aVec.end()) );
+}
+
+void testUniquePtr2()
+{
+o3tl::sorted_vector, 
o3tl::less_uniqueptr_to,
+o3tl::find_partialorder_ptrequals> aVec;
+
+auto str_c = 
aVec.insert(o3tl::make_unique("c")).first->get();
+auto str_b1 = 
aVec.insert(o3tl::make_unique("b")).first->get();
+auto str_b2 = 
aVec.insert(o3tl::make_unique("b")).first->get();
+aVec.insert(o3tl::make_unique("a"));
+CPPUNIT_ASSERT_EQUAL( static_cast(4), aVec.size() );
+CPPUNIT_ASSERT_EQUAL( OUString("a"), *aVec[0] );
+CPPUNIT_ASSERT_EQUAL( OUString("b"), *aVec[1] );
+CPPUNIT_ASSERT_EQUAL( OUString("b"), *aVec[2] );
+CPPUNIT_ASSERT_EQUAL( OUString("c"), *aVec[3] );
+
+CPPUNIT_ASSERT( aVec.find(str_c) != aVec.end() );
+CPPUNIT_ASSERT( aVec.find(str_b1) != aVec.end() );
+CPPUNIT_ASSERT( aVec.find(str_b2) != aVec.end() );
+
+OUString tmp2("z");
+CPPUNIT_ASSERT( bool(aVec.find() == aVec.end()) );
+}
 
 // Change the following lines only, if you add, remove or rename
 // member functions of the current class,
@@ -262,6 +308,8 @@ public:
 CPPUNIT_TEST(testLowerBound);
 CPPUNIT_TEST(testBasics_FindPtr);
 CPPUNIT_TEST(testErase_FindPtr);
+CPPUNIT_TEST(testUniquePtr1);
+CPPUNIT_TEST(testUniquePtr2);
 CPPUNIT_TEST_SUITE_END();
 };
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/o3tl sw/source

2018-09-06 Thread Libreoffice Gerrit user
 include/o3tl/sorted_vector.hxx   |   48 +--
 sw/source/filter/html/htmltabw.cxx   |6 +--
 sw/source/filter/inc/wrtswtbl.hxx|6 +--
 sw/source/filter/writer/wrtswtbl.cxx |   31 +
 sw/source/filter/ww8/docxattributeoutput.cxx |4 +-
 sw/source/filter/ww8/rtfattributeoutput.cxx  |8 ++--
 6 files changed, 74 insertions(+), 29 deletions(-)

New commits:
commit fad919eb0d30b2303193e1c00ba765514957652c
Author: Noel Grandin 
AuthorDate: Mon Sep 3 11:32:58 2018 +0200
Commit: Noel Grandin 
CommitDate: Thu Sep 6 09:41:48 2018 +0200

make SwWriteTableRows be a vector of std::unique_ptr

and update o3tl::sorted_vector to handle that

Change-Id: I11a9ec3ec09f835cbd7e49ccda133b9f210d761e
Reviewed-on: https://gerrit.libreoffice.org/59931
Tested-by: Jenkins
Reviewed-by: Noel Grandin 

diff --git a/include/o3tl/sorted_vector.hxx b/include/o3tl/sorted_vector.hxx
index 9141c592ffd8..254d627604df 100644
--- a/include/o3tl/sorted_vector.hxx
+++ b/include/o3tl/sorted_vector.hxx
@@ -13,6 +13,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 
 namespace o3tl
 {
@@ -27,8 +29,11 @@ struct find_unique;
 @tpl Compare comparison method
 @tpl Find   look up index of a Value in the array
 */
-template,
- template class Find = find_unique >
+template<
+ typename Value,
+ typename Compare = std::less,
+ template class Find = find_unique,
+ bool = std::is_copy_constructible::value >
 class sorted_vector
 {
 private:
@@ -42,6 +47,17 @@ public:
 
 // MODIFIERS
 
+std::pair insert( Value&& x )
+{
+std::pair const ret(Find_t()(m_vector.begin(), 
m_vector.end(), x));
+if (!ret.second)
+{
+const_iterator const it = m_vector.insert(m_vector.begin() + 
(ret.first - m_vector.begin()), std::move(x));
+return std::make_pair(it, true);
+}
+return std::make_pair(ret.first, false);
+}
+
 std::pair insert( const Value& x )
 {
 std::pair const ret(Find_t()(m_vector.begin(), 
m_vector.end(), x));
@@ -197,6 +213,26 @@ private:
 vector_t m_vector;
 };
 
+/* Specialise the template for cases like Value = std::unique_ptr, where
+   MSVC2017 needs some help
+*/
+template<
+ typename Value,
+ typename Compare,
+ template class Find >
+class sorted_vector : public sorted_vector
+{
+public:
+using sorted_vector::sorted_vector;
+
+sorted_vector(sorted_vector const&) = delete;
+sorted_vector& operator=(sorted_vector const&) = delete;
+
+sorted_vector() = default;
+sorted_vector(sorted_vector&&) = default;
+sorted_vector& operator=(sorted_vector&&) = default;
+};
+
 
 /** Implements an ordering function over a pointer, where the comparison uses 
the < operator on the pointed-to types.
 Very useful for the cases where we put pointers to objects inside a 
sorted_vector.
@@ -209,6 +245,14 @@ template  struct less_ptr_to
 }
 };
 
+template  struct less_uniqueptr_to
+{
+bool operator() ( std::unique_ptr const& lhs, std::unique_ptr const& 
rhs ) const
+{
+return (*lhs) < (*rhs);
+}
+};
+
 /** the elements are totally ordered by Compare,
 for no 2 elements !Compare(a,b) && !Compare(b,a) is true
   */
diff --git a/sw/source/filter/html/htmltabw.cxx 
b/sw/source/filter/html/htmltabw.cxx
index 0d400245efb9..d3f76c41adb1 100644
--- a/sw/source/filter/html/htmltabw.cxx
+++ b/sw/source/filter/html/htmltabw.cxx
@@ -564,10 +564,10 @@ void SwHTMLWrtTable::Write( SwHTMLWriter& rWrt, sal_Int16 
eAlign,
 // determine value of RULES
 bool bRowsHaveBorder = false;
 bool bRowsHaveBorderOnly = true;
-SwWriteTableRow *pRow = m_aRows[0];
+SwWriteTableRow *pRow = m_aRows[0].get();
 for( SwWriteTableRows::size_type nRow=1; nRow < m_aRows.size(); ++nRow )
 {
-SwWriteTableRow *pNextRow = m_aRows[nRow];
+SwWriteTableRow *pNextRow = m_aRows[nRow].get();
 bool bBorder = ( pRow->bBottomBorder || pNextRow->bTopBorder );
 bRowsHaveBorder |= bBorder;
 bRowsHaveBorderOnly &= bBorder;
@@ -808,7 +808,7 @@ void SwHTMLWrtTable::Write( SwHTMLWriter& rWrt, sal_Int16 
eAlign,
 
 for( SwWriteTableRows::size_type nRow = 0; nRow < m_aRows.size(); ++nRow )
 {
-const SwWriteTableRow *pRow2 = m_aRows[nRow];
+const SwWriteTableRow *pRow2 = m_aRows[nRow].get();
 
 OutTableCells( rWrt, pRow2->GetCells(), pRow2->GetBackground() );
 if( !m_nCellSpacing && nRow < m_aRows.size()-1 && pRow2->bBottomBorder 
&&
diff --git a/sw/source/filter/inc/wrtswtbl.hxx 
b/sw/source/filter/inc/wrtswtbl.hxx
index 2537dbb5dd29..7c61ba07de8c 100644
--- a/sw/source/filter/inc/wrtswtbl.hxx
+++ b/sw/source/filter/inc/wrtswtbl.hxx
@@ -151,10 +151,8 @@ inline bool SwWriteTableRow::operator<( const 
SwWriteTableRow& rRow ) const
 return nPos < rRow.nPos - (mbUseLayoutHeights ? 0 : ROWFUZZY);
 }
 

[Libreoffice-commits] core.git: include/o3tl

2018-08-29 Thread Libreoffice Gerrit user
 include/o3tl/safeint.hxx |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

New commits:
commit 9ab68b9fb02797f9b5242ae0e7cc406a5a1b1adc
Author: Stephan Bergmann 
AuthorDate: Wed Aug 29 13:49:03 2018 +0200
Commit: Stephan Bergmann 
CommitDate: Wed Aug 29 15:10:16 2018 +0200

32-bit Clang trunk (towards Clang 9) still doesn't have __mulodi4

Change-Id: I7579ff88d34c931a51c820b53960a281e6e3678e
Reviewed-on: https://gerrit.libreoffice.org/59763
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/o3tl/safeint.hxx b/include/o3tl/safeint.hxx
index fa08b6dfc899..6f879965840c 100644
--- a/include/o3tl/safeint.hxx
+++ b/include/o3tl/safeint.hxx
@@ -112,8 +112,8 @@ template inline bool checked_sub(T a, T b, T& 
result)
 return !msl::utilities::SafeSubtract(a, b, result);
 }
 
-#elif (defined __GNUC__ && __GNUC__ >= 5) || 
(__has_builtin(__builtin_mul_overflow) && !(defined ANDROID && defined 
__clang__) && !(defined(__clang__) && defined(__i386__) && __clang_major__ == 
4))
-// 32-bit clang 4.0.1 fails with undefined reference to `__mulodi4'
+#elif (defined __GNUC__ && __GNUC__ >= 5) || 
(__has_builtin(__builtin_mul_overflow) && !(defined ANDROID && defined 
__clang__) && !(defined(__clang__) && defined(__i386__)))
+// 32-bit clang fails with undefined reference to `__mulodi4'
 
 template inline bool checked_multiply(T a, T b, T& result)
 {
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/o3tl writerfilter/source

2018-08-15 Thread Libreoffice Gerrit user
 include/o3tl/clamp.hxx |   43 +
 writerfilter/source/rtftok/rtfdocumentimpl.cxx |9 -
 writerfilter/source/rtftok/rtfdocumentimpl.hxx |8 ++--
 3 files changed, 54 insertions(+), 6 deletions(-)

New commits:
commit 2d2ccd18ead83d1589bc0d71c01d4d79f7ac8bbc
Author: Stephan Bergmann 
AuthorDate: Wed Aug 15 08:23:13 2018 +0200
Commit: Stephan Bergmann 
CommitDate: Wed Aug 15 10:59:00 2018 +0200

RTF picture sizes are 32-bit signed

...not 16-bit unsigned.  Word2007RTFSpec9.docx states "A small number of 
control
words take values in the range −2,147,483,648 to 2,147,483,647 (32-bit 
signed
integer)." and for \picwN, \pichN, \picwgoalN, and \pichgoalN it states 
"The N
argument is a long integer."

This was found with Clang's new -fsanitize=implicit-conversion during
CppunitTest_writerfilter_rtftok, where
writerfilter/qa/cppunittests/rtftok/data/pass/TCI-TN65GP-DDRHDLL-partial.rtf
contains "\pich81306":

> Testing 
file:///home/sbergman/lo/core/writerfilter/qa/cppunittests/rtftok/data/pass/TCI-TN65GP-DDRHDLL-partial.rtf:
[...]
> writerfilter/source/rtftok/rtfdispatchvalue.cxx:770:48: runtime error: 
implicit conversion from type 'int' of value 81306 (32-bit, signed) to type 
'sal_uInt16' (aka 'unsigned short') changed the value to 15770 (16-bit, 
unsigned)
>  #0 in 
writerfilter::rtftok::RTFDocumentImpl::dispatchValue(writerfilter::rtftok::RTFKeyword,
 int) at writerfilter/source/rtftok/rtfdispatchvalue.cxx:770:48 
(instdir/program/libwriterfilterlo.so +0xb96f2f)
>  #1 in writerfilter::rtftok::RTFTokenizer::dispatchKeyword(rtl::OString 
const&, bool, int) at writerfilter/source/rtftok/rtftokenizer.cxx:311:29 
(instdir/program/libwriterfilterlo.so +0xd86c93)
>  #2 in writerfilter::rtftok::RTFTokenizer::resolveKeyword() at 
writerfilter/source/rtftok/rtftokenizer.cxx:243:12 
(instdir/program/libwriterfilterlo.so +0xd84b06)
>  #3 in writerfilter::rtftok::RTFTokenizer::resolveParse() at 
writerfilter/source/rtftok/rtftokenizer.cxx:123:27 
(instdir/program/libwriterfilterlo.so +0xd8299a)
>  #4 in 
writerfilter::rtftok::RTFDocumentImpl::resolve(writerfilter::Stream&) at 
writerfilter/source/rtftok/rtfdocumentimpl.cxx:786:27 
(instdir/program/libwriterfilterlo.so +0xbf03bd)
>  #5 in 
RtfFilter::filter(com::sun::star::uno::Sequence
 const&) at writerfilter/source/filter/RtfFilter.cxx:144:20 
(instdir/program/libwriterfilterlo.so +0x132d911)
>  #6 in RtfTest::load(rtl::OUString const&, rtl::OUString const&, 
rtl::OUString const&, SfxFilterFlags, SotClipboardFormatId, unsigned int) at 
writerfilter/qa/cppunittests/rtftok/testrtftok.cxx:58:27 
(workdir/LinkTarget/CppunitTest/libtest_writerfilter_rtftok.so +0x15c6e)
>  #7 in test::FiltersTest::recursiveScan(test::filterStatus, rtl::OUString 
const&, rtl::OUString const&, rtl::OUString const&, SfxFilterFlags, 
SotClipboardFormatId, unsigned int, bool) at 
unotest/source/cpp/filters-test.cxx:130:20 
(workdir/LinkTarget/CppunitTest/../Library/libunotest.so +0x5724c)
>  #8 in test::FiltersTest::testDir(rtl::OUString const&, rtl::OUString 
const&, rtl::OUString const&, SfxFilterFlags, SotClipboardFormatId, unsigned 
int, bool) at unotest/source/cpp/filters-test.cxx:155:5 
(workdir/LinkTarget/CppunitTest/../Library/libunotest.so +0x57ec9)
>  #9 in RtfTest::test() at 
writerfilter/qa/cppunittests/rtftok/testrtftok.cxx:78:5 
(workdir/LinkTarget/CppunitTest/libtest_writerfilter_rtftok.so +0x16214)

(Needs to add o3tl::clamp as a compatibility wrapper for C++17 std::clamp.)

Change-Id: I515e70a435c2585777062fd5a27d1de8ddbe1b74
Reviewed-on: https://gerrit.libreoffice.org/59038
Reviewed-by: Miklos Vajna 
Tested-by: Jenkins

diff --git a/include/o3tl/clamp.hxx b/include/o3tl/clamp.hxx
new file mode 100644
index ..054de5e22517
--- /dev/null
+++ b/include/o3tl/clamp.hxx
@@ -0,0 +1,43 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; 
fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INCLUDED_O3TL_CLAMP_HXX
+#define INCLUDED_O3TL_CLAMP_HXX
+
+#include 
+
+#include 
+#include 
+
+#include 
+
+// C++17 std::clamp
+
+namespace o3tl
+{
+#if defined __cpp_lib_clamp
+
+using std::clamp;
+
+#else
+
+template  constexpr const T& clamp(const T& v, const T& lo, const 
T& hi)
+{
+#if HAVE_CXX14_CONSTEXPR
+assert(!(hi < lo));
+#endif
+return v < lo ? lo : (hi < v ? hi : v);
+}
+
+#endif
+}
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx 
b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index 

[Libreoffice-commits] core.git: include/o3tl

2018-07-26 Thread Libreoffice Gerrit user
 include/o3tl/array_view.hxx |7 ---
 1 file changed, 7 deletions(-)

New commits:
commit de573ba8e67f165693e58e05d80756e5b55852e7
Author: Stephan Bergmann 
AuthorDate: Thu Jul 26 12:26:24 2018 +0200
Commit: Stephan Bergmann 
CommitDate: Thu Jul 26 20:44:51 2018 +0200

o3tl: avoid -Werror=deprecated-copy (GCC trunk towards GCC 9)

...by removing explicitly user-provided functions that do the same as their
implicitly-defined counterparts, but may prevent implicitly declared copy
functions from being defined as non-deleted in the future

Change-Id: If3430e23fff7bb0da12ae20579696869bdf9b3d8
Reviewed-on: https://gerrit.libreoffice.org/58082
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/o3tl/array_view.hxx b/include/o3tl/array_view.hxx
index 3630955a927b..563821a46f6d 100644
--- a/include/o3tl/array_view.hxx
+++ b/include/o3tl/array_view.hxx
@@ -86,13 +86,6 @@ public:
 return *this;
 }
 
-array_view& operator=(array_view const & other)
-{
-data_ = other.data_;
-size_ = other.size_;
-return *this;
-}
-
 constexpr bool empty() const noexcept { return size_ == 0; }
 
 constexpr iterator begin() const noexcept { return data_; }
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/o3tl

2018-06-04 Thread Michael Stahl
 include/o3tl/strong_int.hxx |9 +
 1 file changed, 9 insertions(+)

New commits:
commit 98e4c241e9ef918c739638154b7ba850d70e0eed
Author: Michael Stahl 
Date:   Thu May 3 12:27:31 2018 +0200

o3tl: add more strong_int operators

Change-Id: Ibb0f883353b6d172275744eaa59d27ba39930623
Reviewed-on: https://gerrit.libreoffice.org/55264
Tested-by: Jenkins 
Reviewed-by: Michael Stahl 

diff --git a/include/o3tl/strong_int.hxx b/include/o3tl/strong_int.hxx
index bdb60b30fb69..fb00addfad08 100644
--- a/include/o3tl/strong_int.hxx
+++ b/include/o3tl/strong_int.hxx
@@ -110,6 +110,10 @@ public:
 bool operator!=(strong_int const & other) const { return m_value != 
other.m_value; }
 strong_int& operator++() { ++m_value; return *this; }
 strong_int operator++(int) { UNDERLYING_TYPE nOldValue = m_value; 
++m_value; return strong_int(nOldValue); }
+strong_int& operator--() { --m_value; return *this; }
+strong_int operator--(int) { UNDERLYING_TYPE nOldValue = m_value; 
--m_value; return strong_int(nOldValue); }
+strong_int& operator+=(strong_int const & other) { m_value += 
other.m_value; return *this; }
+strong_int& operator-=(strong_int const & other) { m_value -= 
other.m_value; return *this; }
 
 bool anyOf(strong_int v) const {
   return *this == v;
@@ -130,6 +134,11 @@ strong_int operator+(strong_int const & lhs, 
strong_int con
 return strong_int(lhs.get() + rhs.get());
 }
 
+template 
+strong_int operator-(strong_int const & lhs, strong_int 
const & rhs)
+{
+return strong_int(lhs.get() - rhs.get());
+}
 
 }; // namespace o3tl
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/o3tl vcl/win

2018-04-11 Thread Noel Grandin
 include/o3tl/lru_map.hxx |3 ++-
 vcl/win/gdi/salfont.cxx  |8 +++-
 2 files changed, 5 insertions(+), 6 deletions(-)

New commits:
commit 8094fa17207729c119f7a1fa399286919dd1a8a3
Author: Noel Grandin 
Date:   Wed Apr 11 15:53:35 2018 +0200

improve commit 95eb921ec06ee7

   "tdf#108608 more Draw text editing responsiveness fixes"

lru_map is fine on Windows, was a bug in the new clear method I
added.

Change-Id: I27565675dfe0f57e2ba3c3e0c50297770761dc6a
Reviewed-on: https://gerrit.libreoffice.org/52728
Tested-by: Jenkins 
Reviewed-by: Noel Grandin 

diff --git a/include/o3tl/lru_map.hxx b/include/o3tl/lru_map.hxx
index 4eb05bd97a43..f2369e45030a 100644
--- a/include/o3tl/lru_map.hxx
+++ b/include/o3tl/lru_map.hxx
@@ -125,7 +125,7 @@ public:
 
 const list_const_iterator_t end() const
 {
-return mLruList.end();
+return mLruList.cend();
 }
 
 size_t size() const
@@ -135,6 +135,7 @@ public:
 
 void clear()
 {
+mLruMap.clear();
 mLruList.clear();
 }
 };
diff --git a/vcl/win/gdi/salfont.cxx b/vcl/win/gdi/salfont.cxx
index e415ec8fa1b3..7c6bb027f245 100644
--- a/vcl/win/gdi/salfont.cxx
+++ b/vcl/win/gdi/salfont.cxx
@@ -28,6 +28,7 @@
 #include 
 #include 
 
+#include 
 #include 
 #include 
 #include 
@@ -57,10 +58,9 @@
 using namespace vcl;
 
 // GetGlyphOutlineW() seems to be a little slow, and doesn't seem to do it's 
own caching (tested on Windows10).
-// TODO use something a little smarter here like an LRU cache, and include the 
font as part of the cache key
+// TODO include the font as part of the cache key, then we won't need to clear 
it on font change
 // The cache limit is set by the rough number of characters needed to read 
your average Asian newspaper.
-constexpr size_t BOUND_RECT_CACHE_SIZE = 3000;
-static std::unordered_map g_BoundRectCache;
+static o3tl::lru_map g_BoundRectCache(3000);
 
 inline FIXED FixedFromDouble( double d )
 {
@@ -1340,8 +1340,6 @@ bool WinSalGraphics::GetGlyphBoundRect(const GlyphItem& 
rGlyph, tools::Rectangle
 rRect = it->second;
 return true;
 }
-if (g_BoundRectCache.size() > BOUND_RECT_CACHE_SIZE)
-g_BoundRectCache.clear();
 
 HDC hDC = getHDC();
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/o3tl vcl/win

2018-04-11 Thread Noel Grandin
 include/o3tl/lru_map.hxx |5 +
 vcl/win/gdi/salfont.cxx  |   19 +++
 2 files changed, 24 insertions(+)

New commits:
commit 8a94d3dcfa0c37685afd5f966d7fdc1d25dc923d
Author: Noel Grandin 
Date:   Mon Apr 9 11:16:59 2018 +0200

tdf#108608 more Draw text editing responsiveness fixes

Turns out Windows is rather slow at at calculating glyph outlines
(compared to Linux), I'm guessing it does no caching at all, so
just add our own little cache.

I tried to use o3tl::lru_map here, but it crashes under MSVC2015.

Change-Id: I78d2a787ec8f734fa821f41f13236771efa1c8d4
Reviewed-on: https://gerrit.libreoffice.org/52623
Tested-by: Jenkins 
Reviewed-by: Noel Grandin 

diff --git a/include/o3tl/lru_map.hxx b/include/o3tl/lru_map.hxx
index 2f41521795fc..4eb05bd97a43 100644
--- a/include/o3tl/lru_map.hxx
+++ b/include/o3tl/lru_map.hxx
@@ -132,6 +132,11 @@ public:
 {
 return mLruList.size();
 }
+
+void clear()
+{
+mLruList.clear();
+}
 };
 
 }
diff --git a/vcl/win/gdi/salfont.cxx b/vcl/win/gdi/salfont.cxx
index 9dbde8fd52d7..e415ec8fa1b3 100644
--- a/vcl/win/gdi/salfont.cxx
+++ b/vcl/win/gdi/salfont.cxx
@@ -56,6 +56,11 @@
 
 using namespace vcl;
 
+// GetGlyphOutlineW() seems to be a little slow, and doesn't seem to do it's 
own caching (tested on Windows10).
+// TODO use something a little smarter here like an LRU cache, and include the 
font as part of the cache key
+// The cache limit is set by the rough number of characters needed to read 
your average Asian newspaper.
+constexpr size_t BOUND_RECT_CACHE_SIZE = 3000;
+static std::unordered_map g_BoundRectCache;
 
 inline FIXED FixedFromDouble( double d )
 {
@@ -835,6 +840,9 @@ void ImplGetLogFontFromFontSelect( HDC hDC,
 
 HFONT WinSalGraphics::ImplDoSetFont(FontSelectPattern const * i_pFont, HFONT& 
o_rOldFont)
 {
+// clear the cache on font change
+g_BoundRectCache.clear();
+
 HFONT hNewFont = nullptr;
 
 HDC hdcScreen = nullptr;
@@ -1326,6 +1334,15 @@ void WinSalGraphics::ClearDevFontCache()
 
 bool WinSalGraphics::GetGlyphBoundRect(const GlyphItem& rGlyph, 
tools::Rectangle& rRect)
 {
+auto it = g_BoundRectCache.find(rGlyph.maGlyphId);
+if (it != g_BoundRectCache.end())
+{
+rRect = it->second;
+return true;
+}
+if (g_BoundRectCache.size() > BOUND_RECT_CACHE_SIZE)
+g_BoundRectCache.clear();
+
 HDC hDC = getHDC();
 
 // use unity matrix
@@ -1347,6 +1364,8 @@ bool WinSalGraphics::GetGlyphBoundRect(const GlyphItem& 
rGlyph, tools::Rectangle
 Size( aGM.gmBlackBoxX, aGM.gmBlackBoxY ) );
 rRect.AdjustRight(1);
 rRect.AdjustBottom(1);
+
+g_BoundRectCache.insert({rGlyph.maGlyphId, rRect});
 return true;
 }
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/o3tl svx/source

2018-02-19 Thread Caolán McNamara
 include/o3tl/deleter.hxx |   10 ++
 svx/source/svdraw/svdobj.cxx |3 ++-
 svx/source/svdraw/svdobjplusdata.cxx |8 ++--
 3 files changed, 14 insertions(+), 7 deletions(-)

New commits:
commit b99af181a40b464218434e8cf4167cb69c4383df
Author: Caolán McNamara 
Date:   Mon Feb 19 12:39:46 2018 +

ofz#6432 bad-cast

ofz#6433 head-use-after-free
ofz#6435 bad-cast

Change-Id: Ic43edbab68d96e852039c3247853074180fd5091
Reviewed-on: https://gerrit.libreoffice.org/49984
Tested-by: Jenkins 
Reviewed-by: Caolán McNamara 
Tested-by: Caolán McNamara 

diff --git a/include/o3tl/deleter.hxx b/include/o3tl/deleter.hxx
index 5b5e67929a15..af06ffa1267c 100644
--- a/include/o3tl/deleter.hxx
+++ b/include/o3tl/deleter.hxx
@@ -43,6 +43,16 @@ template struct default_delete
 }
 };
 
+template void reset_preserve_ptr_during(uniqueptr& ptr)
+{
+// HACK: for the case where the dtor of the obj held by ptr will trigger
+// functions which expect ptr to still be set during the dtor.
+// e.g. SdrObject::GetBroadcaster() is called during the destructor
+// in SdrEdgeObj::Notify(). So delete first, then clear the pointer
+delete ptr.get();
+(void)ptr.release();
+}
+
 }
 
 #endif
diff --git a/svx/source/svdraw/svdobj.cxx b/svx/source/svdraw/svdobj.cxx
index 7daf499746de..612f01ab4d1f 100644
--- a/svx/source/svdraw/svdobj.cxx
+++ b/svx/source/svdraw/svdobj.cxx
@@ -39,6 +39,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -358,7 +359,7 @@ SdrObject::~SdrObject()
 }
 
 SendUserCall(SdrUserCallType::Delete, GetLastBoundRect());
-pPlusData.reset();
+o3tl::reset_preserve_ptr_during(pPlusData);
 
 pGrabBagItem.reset();
 mpProperties.reset();
diff --git a/svx/source/svdraw/svdobjplusdata.cxx 
b/svx/source/svdraw/svdobjplusdata.cxx
index c7a74a5cc4c9..ee7a801cd8e4 100644
--- a/svx/source/svdraw/svdobjplusdata.cxx
+++ b/svx/source/svdraw/svdobjplusdata.cxx
@@ -9,9 +9,8 @@
 
 #include 
 #include 
-
+#include 
 #include 
-
 #include 
 #include 
 
@@ -24,10 +23,7 @@ SdrObjPlusData::SdrObjPlusData():
 
 SdrObjPlusData::~SdrObjPlusData()
 {
-// HACK: the SdrObject::GetBroadcaster() is called during the destructor
-// in SdrEdgeObj::Notify() so delete first, then clear the pointer
-delete pBroadcast.get();
-(void) pBroadcast.release();
+o3tl::reset_preserve_ptr_during(pBroadcast);
 pUserDataList.reset();
 pGluePoints.reset();
 }
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/o3tl sot/qa sot/source

2018-02-07 Thread Caolán McNamara
 include/o3tl/sorted_vector.hxx   |5 +
 sot/qa/cppunit/data/pass/badchain-1.compound |binary
 sot/qa/cppunit/test_sot.cxx  |1 
 sot/source/sdstor/stgdir.cxx |3 
 sot/source/sdstor/stgstrms.cxx   |   94 +++
 sot/source/sdstor/stgstrms.hxx   |   12 ++-
 6 files changed, 68 insertions(+), 47 deletions(-)

New commits:
commit e89964ebb3ba3bd7d694695c004c5f976d8d9616
Author: Caolán McNamara 
Date:   Tue Feb 6 15:36:07 2018 +

ofz: Pos2Page returns true on same value that returned false previously

a failed position returns false, but stays at the failed position, so
next time its called without moving it then it returns true

store what we return for a given position for reuse if the position
doesn't change

Change-Id: I404c65ac89eb6f5c867f62a62028b87effdbcbf8
Reviewed-on: https://gerrit.libreoffice.org/49308
Tested-by: Jenkins 
Reviewed-by: Caolán McNamara 
Tested-by: Caolán McNamara 

diff --git a/include/o3tl/sorted_vector.hxx b/include/o3tl/sorted_vector.hxx
index 7a9ca4568032..9141c592ffd8 100644
--- a/include/o3tl/sorted_vector.hxx
+++ b/include/o3tl/sorted_vector.hxx
@@ -86,6 +86,11 @@ public:
 m_vector.clear();
 }
 
+void reserve(size_type amount)
+{
+m_vector.reserve(amount);
+}
+
 // ACCESSORS
 
 size_type size() const
diff --git a/sot/qa/cppunit/data/pass/badchain-1.compound 
b/sot/qa/cppunit/data/pass/badchain-1.compound
new file mode 100644
index ..4c70faf207fd
Binary files /dev/null and b/sot/qa/cppunit/data/pass/badchain-1.compound differ
diff --git a/sot/qa/cppunit/test_sot.cxx b/sot/qa/cppunit/test_sot.cxx
index c4e961271801..0ffbe758a1ec 100644
--- a/sot/qa/cppunit/test_sot.cxx
+++ b/sot/qa/cppunit/test_sot.cxx
@@ -63,7 +63,6 @@ namespace
 
 // Read as much as we can, a corrupted FAT chain can cause real 
grief here
 nReadableSize = xStream->ReadBytes(static_cast(pData), 
nSize);
-//fprintf(stderr, "readable size %d vs size %d remaining %d\n", 
nReadableSize, nSize, nReadableSize);
 }
 {   // Read the data backwards as well
 tools::SvRef xStream( xObjStor->OpenSotStream( 
rStreamName ) );
diff --git a/sot/source/sdstor/stgdir.cxx b/sot/source/sdstor/stgdir.cxx
index 253fb4399d05..b2e64967c436 100644
--- a/sot/source/sdstor/stgdir.cxx
+++ b/sot/source/sdstor/stgdir.cxx
@@ -839,7 +839,8 @@ bool StgDirStrm::Store()
 sal_Int32 nOldStart = m_nStart;   // save for later deletion
 sal_Int32 nOldSize  = m_nSize;
 m_nStart = m_nPage = STG_EOF;
-m_nSize  = m_nPos = 0;
+m_nSize = 0;
+SetPos(0, true);
 m_nOffset = 0;
 // Delete all temporary entries
 m_pRoot->DelTemp( false );
diff --git a/sot/source/sdstor/stgstrms.cxx b/sot/source/sdstor/stgstrms.cxx
index 8e5093fe9a91..a9e7217a3a21 100644
--- a/sot/source/sdstor/stgstrms.cxx
+++ b/sot/source/sdstor/stgstrms.cxx
@@ -322,11 +322,12 @@ bool StgFAT::FreePages( sal_Int32 nStart, bool bAll )
 // FAT class for the page allocations.
 
 StgStrm::StgStrm( StgIo& r )
-: m_rIo(r),
+: m_nPos(0),
+  m_bBytePosValid(true),
+  m_rIo(r),
   m_pEntry(nullptr),
   m_nStart(STG_EOF),
   m_nSize(0),
-  m_nPos(0),
   m_nPage(STG_EOF),
   m_nOffset(0),
   m_nPageSize(m_rIo.GetPhysPageSize())
@@ -356,7 +357,10 @@ void StgStrm::SetEntry( StgDirEntry& r )
 sal_Int32 StgStrm::scanBuildPageChainCache()
 {
 if (m_nSize > 0)
+{
 m_aPagesCache.reserve(m_nSize/m_nPageSize);
+m_aUsedPageNumbers.reserve(m_nSize/m_nPageSize);
+}
 
 bool bError = false;
 sal_Int32 nBgn = m_nStart;
@@ -364,8 +368,6 @@ sal_Int32 StgStrm::scanBuildPageChainCache()
 
 // Track already scanned PageNumbers here and use them to
 // see if an  already counted page is re-visited
-std::set< sal_Int32 > nUsedPageNumbers;
-
 while( nBgn >= 0 && !bError )
 {
 if( nBgn >= 0 )
@@ -373,7 +375,7 @@ sal_Int32 StgStrm::scanBuildPageChainCache()
 nBgn = m_pFat->GetNextPage( nBgn );
 
 //returned second is false if it already exists
-if (!nUsedPageNumbers.insert(nBgn).second)
+if (!m_aUsedPageNumbers.insert(nBgn).second)
 {
 SAL_WARN ("sot", "Error: page number " << nBgn << " already in 
chain for stream");
 bError = true;
@@ -386,6 +388,7 @@ sal_Int32 StgStrm::scanBuildPageChainCache()
 SAL_WARN("sot", "returning wrong format error");
 m_rIo.SetError( ERRCODE_IO_WRONGFORMAT );
 m_aPagesCache.clear();
+m_aUsedPageNumbers.clear();
 }
 return nOptSize;
 }
@@ -408,8 +411,8 @@ bool StgStrm::Pos2Page( sal_Int32 nBytePos )
 sal_Int32 nNew = nBytePos & nMask;
 m_nOffset = static_cast( nBytePos & ~nMask );
 m_nPos = 

[Libreoffice-commits] core.git: include/o3tl

2018-02-01 Thread Mike Kaganski
 include/o3tl/array_view.hxx  |4 ++--
 include/o3tl/string_view.hxx |9 -
 2 files changed, 2 insertions(+), 11 deletions(-)

New commits:
commit 1e96364cf016097ab01ef933fff02f629e7b1884
Author: Mike Kaganski 
Date:   Wed Jan 31 20:39:33 2018 +0300

o3tl: MSVC: pragma warning: make more specific, remove obsolete

Change-Id: Id9d038d50d5b6335a2f354c759b2c1e5dd413cec
Reviewed-on: https://gerrit.libreoffice.org/49037
Tested-by: Jenkins 
Reviewed-by: Mike Kaganski 

diff --git a/include/o3tl/array_view.hxx b/include/o3tl/array_view.hxx
index 2913010fab89..3630955a927b 100644
--- a/include/o3tl/array_view.hxx
+++ b/include/o3tl/array_view.hxx
@@ -36,8 +36,8 @@
 namespace o3tl {
 
 #if defined _MSC_VER
-#pragma warning(push, 1)
-#pragma warning(disable: 4814) // in C++14 'constexpr' will not imply 'const'
+#pragma warning(push)
+#pragma warning(disable: 4522) // multiple assignment operators specified
 #endif
 
 /** A barebones approximation of C++17(?) .
diff --git a/include/o3tl/string_view.hxx b/include/o3tl/string_view.hxx
index ae284b20173d..303e4800af79 100644
--- a/include/o3tl/string_view.hxx
+++ b/include/o3tl/string_view.hxx
@@ -152,11 +152,6 @@ template struct 
ConstWcharArrayDetector {
 
 }
 
-#if defined _MSC_VER
-#pragma warning(push, 1)
-#pragma warning(disable: 4814) // in C++14 'constexpr' will not imply 'const'
-#endif
-
 template>
 class basic_string_view {
 public:
@@ -825,10 +820,6 @@ operator <<(
 return os;
 }
 
-#if defined _MSC_VER
-#pragma warning(pop)
-#endif
-
 using string_view = basic_string_view;
 using u16string_view = basic_string_view;
 using u32string_view = basic_string_view;
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/o3tl include/salhelper include/svx include/ucbhelper include/vcl sw/source

2018-01-29 Thread Andrea Gelmini
 include/o3tl/any.hxx |6 +++---
 include/salhelper/dynload.hxx|2 +-
 include/svx/DescriptionGenerator.hxx |6 +++---
 include/ucbhelper/simpleauthenticationrequest.hxx|2 +-
 include/ucbhelper/simplecertificatevalidationrequest.hxx |2 +-
 include/vcl/outdev.hxx   |2 +-
 include/vcl/svapp.hxx|2 +-
 sw/source/core/inc/UndoInsert.hxx|2 +-
 8 files changed, 12 insertions(+), 12 deletions(-)

New commits:
commit 9ec6f974a32f7bac1393d8d36305b9d4c082f4f8
Author: Andrea Gelmini 
Date:   Mon Jan 29 14:00:48 2018 +0100

Fix typos

Change-Id: I4f15a41b7a67abe9f2c45b6004948decd58a8360
Reviewed-on: https://gerrit.libreoffice.org/48832
Reviewed-by: Julien Nabet 
Tested-by: Julien Nabet 

diff --git a/include/o3tl/any.hxx b/include/o3tl/any.hxx
index 85fd28106419..141d788e15c4 100644
--- a/include/o3tl/any.hxx
+++ b/include/o3tl/any.hxx
@@ -136,7 +136,7 @@ template inline boost::optional 
tryGetConverted(
 
 @param any  an Any value.
 
-@return a positive proxy for the value of the specfied type obtained from
+@return a positive proxy for the value of the specified type obtained from
 the given Any, or a negative proxy if no such value can be obtained.
 */
 template inline
@@ -270,7 +270,7 @@ template typename detail::Optional::type 
tryAccess(
 
 @param any  an Any value.
 
-@return a positive proxy for the value of the specfied type obtained from
+@return a positive proxy for the value of the specified type obtained from
 the given Any.  See tryAccess for details.
 
 @throws css::uno::RuntimeException  when a value of the requested type
@@ -307,7 +307,7 @@ template inline typename 
detail::Optional::type doAccess(
 
 @param any  an Any value.
 
-@return a positive proxy for the value of the specfied type obtained from
+@return a positive proxy for the value of the specified type obtained from
 the given Any.  See tryAccess for details.
 */
 template inline typename detail::Optional::type forceAccess(
diff --git a/include/salhelper/dynload.hxx b/include/salhelper/dynload.hxx
index 98fe9af1f0ed..12d54d5cffa4 100644
--- a/include/salhelper/dynload.hxx
+++ b/include/salhelper/dynload.hxx
@@ -111,7 +111,7 @@ public:
 m_pLoader = NULL;
 }
 
-/** Constructor, loads the library if necessary otherwise the refernece 
count will
+/** Constructor, loads the library if necessary otherwise the reference 
count will
 be increased.
 
 @param strModuleName specifies the library name.
diff --git a/include/svx/DescriptionGenerator.hxx 
b/include/svx/DescriptionGenerator.hxx
index fd1b1e2a39ad..6a7b57fc6bde 100644
--- a/include/svx/DescriptionGenerator.hxx
+++ b/include/svx/DescriptionGenerator.hxx
@@ -47,7 +47,7 @@ public:
 };
 
 /** Creates a new description generator with an empty description
-string.  Usually you will want to call initialize next to specifiy
+string.  Usually you will want to call initialize next to specify
 a general description of the shape.
 @param xShape
 The shape from which properties will be extracted by later calls
@@ -59,7 +59,7 @@ public:
 ~DescriptionGenerator();
 
 /** Initialize the description with the given prefix followed by the
-shape's style in parantheses and a colon.
+shape style in parentheses and a colon.
 @param sPrefix
 An introductory description of the shape that is made more
 specific by later calls to addProperty.
@@ -67,7 +67,7 @@ public:
 void Initialize (const OUString& sPrefix);
 
 /** Initialize the description with the specified string from the
-resource followed by the shape's style in parantheses and a colon.
+resource followed by the shape style in parentheses and a colon.
 @param pResourceId
 A resource id the specifies the introductory description of the
 shape that is made more specific by later calls to
diff --git a/include/ucbhelper/simpleauthenticationrequest.hxx 
b/include/ucbhelper/simpleauthenticationrequest.hxx
index b6b2f870f6a6..59d22b3da440 100644
--- a/include/ucbhelper/simpleauthenticationrequest.hxx
+++ b/include/ucbhelper/simpleauthenticationrequest.hxx
@@ -36,7 +36,7 @@ namespace ucbhelper {
   * instance contains an AuthenticationRequest and three interaction
   * continuations: "Abort", "Retry" and "SupplyAuthentication". The parameters
   * for the AuthenticationRequest and the InteractionSupplyAuthentication
-  * objects are partly taken from contructors parameters and partly defaulted
+  * objects are partly taken from constructors parameters and partly defaulted
   * as follows:
   *
   * Read-only values : 

[Libreoffice-commits] core.git: include/o3tl xmloff/source

2018-01-28 Thread Caolán McNamara
 include/o3tl/safeint.hxx|   30 ++
 xmloff/source/draw/ximpshap.cxx |8 
 2 files changed, 34 insertions(+), 4 deletions(-)

New commits:
commit 94823392874be9c9249e312f6783394edf0e731f
Author: Caolán McNamara 
Date:   Sun Jan 28 14:15:44 2018 +

ofz#5621 Integer-overflow

Change-Id: Ie0a7c29428e686e5c480997b84b8d12e5be4539f
Reviewed-on: https://gerrit.libreoffice.org/48790
Tested-by: Jenkins 
Reviewed-by: Caolán McNamara 
Tested-by: Caolán McNamara 

diff --git a/include/o3tl/safeint.hxx b/include/o3tl/safeint.hxx
index 67af99cf810c..fa08b6dfc899 100644
--- a/include/o3tl/safeint.hxx
+++ b/include/o3tl/safeint.hxx
@@ -57,6 +57,36 @@ typename std::enable_if::type 
saturating_add(
 }
 
 template inline
+typename std::enable_if::type saturating_sub(
+T a, T b)
+{
+if (b >= 0) {
+if (a >= std::numeric_limits::min() + b) {
+return a - b;
+} else {
+return std::numeric_limits::min();
+}
+} else {
+if (a <= std::numeric_limits::max() + b) {
+return a - b;
+} else {
+return std::numeric_limits::max();
+}
+}
+}
+
+template inline
+typename std::enable_if::type saturating_sub(
+T a, T b)
+{
+if (a >= std::numeric_limits::min() + b) {
+return a - b;
+} else {
+return std::numeric_limits::min();
+}
+}
+
+template inline
 typename std::enable_if::type 
saturating_toggle_sign(
 T a)
 {
diff --git a/xmloff/source/draw/ximpshap.cxx b/xmloff/source/draw/ximpshap.cxx
index 616dec4d1ba2..4ccdb68d5ff1 100644
--- a/xmloff/source/draw/ximpshap.cxx
+++ b/xmloff/source/draw/ximpshap.cxx
@@ -1083,16 +1083,16 @@ void SdXMLLineShapeContext::StartElement(const 
uno::Reference< xml::sax::XAttrib
 pOuterSequence->realloc(2);
 awt::Point* pInnerSequence = pOuterSequence->getArray();
 
-*pInnerSequence = awt::Point(o3tl::saturating_add(mnX1, -aTopLeft.X), 
o3tl::saturating_add(mnY1, -aTopLeft.Y));
+*pInnerSequence = awt::Point(o3tl::saturating_sub(mnX1, aTopLeft.X), 
o3tl::saturating_sub(mnY1, aTopLeft.Y));
 pInnerSequence++;
-*pInnerSequence = awt::Point(o3tl::saturating_add(mnX2, -aTopLeft.X), 
o3tl::saturating_add(mnY2, -aTopLeft.Y));
+*pInnerSequence = awt::Point(o3tl::saturating_sub(mnX2, aTopLeft.X), 
o3tl::saturating_sub(mnY2, aTopLeft.Y));
 
 xPropSet->setPropertyValue("Geometry", Any(aPolyPoly));
 }
 
 // set sizes for transformation
-maSize.Width = o3tl::saturating_add(aBottomRight.X, -aTopLeft.X);
-maSize.Height = o3tl::saturating_add(aBottomRight.Y, -aTopLeft.Y);
+maSize.Width = o3tl::saturating_sub(aBottomRight.X, aTopLeft.X);
+maSize.Height = o3tl::saturating_sub(aBottomRight.Y, aTopLeft.Y);
 maPosition.X = aTopLeft.X;
 maPosition.Y = aTopLeft.Y;
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


  1   2   >