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

2021-08-18 Thread Noel Grandin (via logerrit)
 include/editeng/outlobj.hxx  |   90 +--
 include/o3tl/cow_wrapper.hxx |   27 
 2 files changed, 113 insertions(+), 4 deletions(-)

New commits:
commit 62d11b0e072b2f34b9f52c33a73cbb54d8112307
Author: Noel Grandin 
AuthorDate: Mon Aug 16 18:47:58 2021 +0200
Commit: Noel Grandin 
CommitDate: Wed Aug 18 12:09:09 2021 +0200

specialise std::optional for OutlineParaObject

we can re-use the o3tl::wrapper pointer to indicate empty

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

diff --git a/include/editeng/outlobj.hxx b/include/editeng/outlobj.hxx
index fac9bed9ffb9..8ba1dedb3f16 100644
--- a/include/editeng/outlobj.hxx
+++ b/include/editeng/outlobj.hxx
@@ -17,8 +17,7 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
 
-#ifndef INCLUDED_EDITENG_OUTLOBJ_HXX
-#define INCLUDED_EDITENG_OUTLOBJ_HXX
+#pragma once
 
 #include 
 #include 
@@ -26,6 +25,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 class EditTextObject;
@@ -36,7 +36,7 @@ enum class TextRotation;
  * This is the guts of OutlinerParaObject, refcounted and shared among
  * multiple instances of OutlinerParaObject.
  */
-struct OutlinerParaObjData
+struct EDITENG_DLLPUBLIC OutlinerParaObjData
 {
 // data members
 std::unique_ptr  mpEditTextObject;
@@ -64,8 +64,14 @@ struct OutlinerParaObjData
 
 class EDITENG_DLLPUBLIC OutlinerParaObject
 {
+friend class std::optional;
 ::o3tl::cow_wrapper< OutlinerParaObjData > mpImpl;
 
+OutlinerParaObject(std::nullopt_t) noexcept
+: mpImpl(std::nullopt) {}
+OutlinerParaObject( const OutlinerParaObject& other, std::nullopt_t ) 
noexcept
+: mpImpl(other.mpImpl, std::nullopt) {}
+
 public:
 // constructors/destructor
 OutlinerParaObject(std::unique_ptr, const 
ParagraphDataVector&, bool bIsEditDoc);
@@ -117,6 +123,82 @@ public:
 void dumpAsXml(xmlTextWriterPtr pWriter) const;
 };
 
-#endif
+namespace std
+{
+/** Specialise std::optional template for the case where we are wrapping a 
o3tl::cow_wrapper
+type, and we can make the pointer inside the cow_wrapper act as an 
empty value,
+and save ourselves some storage */
+template<>
+class optional
+{
+public:
+optional() noexcept : maParaObject(std::nullopt) {}
+optional(std::nullopt_t) noexcept : maParaObject(std::nullopt) {}
+optional(const optional& other) :
+maParaObject(other.maParaObject, std::nullopt) {}
+optional(optional&& other) noexcept :
+maParaObject(std::move(other.maParaObject)) {}
+optional(OutlinerParaObject&& para) noexcept :
+maParaObject(std::move(para)) {}
+optional(const OutlinerParaObject& para) noexcept :
+maParaObject(para) {}
+template< class... Args >
+explicit optional( std::in_place_t, Args&&... args ) :
+maParaObject(std::forward(args)...) {}
+
+optional& operator=(optional const & other)
+{
+maParaObject = other.maParaObject;
+return *this;
+}
+optional& operator=(optional&& other) noexcept
+{
+maParaObject = std::move(other.maParaObject);
+return *this;
+}
+template< class... Args >
+void emplace(Args&&... args )
+{
+maParaObject = OutlinerParaObject(std::forward(args)...);
+}
+
+bool has_value() const noexcept { return !maParaObject.mpImpl.empty(); 
}
+explicit operator bool() const noexcept { return 
!maParaObject.mpImpl.empty(); }
+void reset() { maParaObject.mpImpl.set_empty(); }
+
+OutlinerParaObject& value()
+{
+throwIfEmpty();
+return maParaObject;
+}
+OutlinerParaObject& operator*()
+{
+throwIfEmpty();
+return maParaObject;
+}
+const OutlinerParaObject& operator*() const
+{
+throwIfEmpty();
+return maParaObject;
+}
+OutlinerParaObject* operator->()
+{
+throwIfEmpty();
+return 
+}
+const OutlinerParaObject* operator->() const
+{
+throwIfEmpty();
+return 
+}
+private:
+void throwIfEmpty() const
+{
+if (maParaObject.mpImpl.empty())
+throw std::logic_error("empty 
std::optional");
+}
+OutlinerParaObject maParaObject;
+};
+};
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/o3tl/cow_wrapper.hxx b/include/o3tl/cow_wrapper.hxx
index c05d28699259..ced27c1fda32 100644
--- a/include/o3tl/cow_wrapper.hxx
+++ b/include/o3tl/cow_wrapper.hxx
@@ -22,6 +22,7 @@
 
 #include 
 
+#include 
 #include 
 #include 
 
@@ -252,6 

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

2019-11-06 Thread Caolán McNamara (via logerrit)
 include/editeng/outlobj.hxx  |2 ++
 include/o3tl/cow_wrapper.hxx |   13 +
 2 files changed, 15 insertions(+)

New commits:
commit 8cdf166552aea7cb3dbdc183b76b5457c6651cf7
Author: Caolán McNamara 
AuthorDate: Wed Nov 6 09:51:48 2019 +
Commit: Caolán McNamara 
CommitDate: Wed Nov 6 11:44:46 2019 +0100

ofz#12553 Timeout

before:

real1m37.479s
user1m30.682s
sys 0m0.261s

after:

real0m44.166s
user0m44.010s
sys 0m0.056s

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

diff --git a/include/editeng/outlobj.hxx b/include/editeng/outlobj.hxx
index 364ec740b57f..a28e255634e5 100644
--- a/include/editeng/outlobj.hxx
+++ b/include/editeng/outlobj.hxx
@@ -47,6 +47,8 @@ struct OutlinerParaObjData
 
 OutlinerParaObjData( const OutlinerParaObjData& r );
 
+OutlinerParaObjData( OutlinerParaObjData&& r ) = default;
+
 // assignment operator
 OutlinerParaObjData& operator=(const OutlinerParaObjData& rCandidate) = 
delete;
 
diff --git a/include/o3tl/cow_wrapper.hxx b/include/o3tl/cow_wrapper.hxx
index 2fa7f03f276f..b9c463b852e4 100644
--- a/include/o3tl/cow_wrapper.hxx
+++ b/include/o3tl/cow_wrapper.hxx
@@ -194,6 +194,12 @@ int cow_wrapper_client::queryUnmodified() const
 {
 }
 
+explicit impl_t( T&& v ) :
+m_value(std::move(v)),
+m_ref_count(1)
+{
+}
+
 T  m_value;
 typename MTPolicy::ref_count_t m_ref_count;
 };
@@ -227,6 +233,13 @@ int cow_wrapper_client::queryUnmodified() const
 {
 }
 
+/** Move-construct wrapped type instance from given object
+ */
+explicit cow_wrapper( value_type&& r ) :
+m_pimpl( new impl_t(std::move(r)) )
+{
+}
+
 /** Shallow-copy given cow_wrapper
  */
 explicit cow_wrapper( const cow_wrapper& rSrc ) : // nothrow
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits