include/sfx2/basedlgs.hxx       |    2 
 include/svl/itemset.hxx         |   20 ++---
 include/svl/whichranges.hxx     |   46 +++++++++++--
 solenv/gdb/libreoffice/svl.py   |    4 -
 svl/source/inc/items_helper.hxx |   60 -----------------
 svl/source/items/itemset.cxx    |  141 +++++++++++++++++++++-------------------
 svl/source/items/whiter.cxx     |    8 +-
 sw/source/uibase/inc/tabsh.hxx  |    2 
 8 files changed, 134 insertions(+), 149 deletions(-)

New commits:
commit 73567d60a1c4d2dded06f49df1fae95467e558c3
Author:     Armin Le Grand (allotropia) <armin.le.grand.ext...@allotropia.de>
AuthorDate: Mon Mar 18 20:36:45 2024 +0100
Commit:     Armin Le Grand <armin.le.gr...@me.com>
CommitDate: Tue Mar 19 10:43:03 2024 +0100

    ITEM: Move TotalCount to WhichRangesContainer
    
    Change-Id: I2ab1cd2d0be81b15b4701581093b696aaac2846c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164979
    Tested-by: Jenkins
    Reviewed-by: Armin Le Grand <armin.le.gr...@me.com>

diff --git a/include/sfx2/basedlgs.hxx b/include/sfx2/basedlgs.hxx
index e182b9aa7789..0805e55264e7 100644
--- a/include/sfx2/basedlgs.hxx
+++ b/include/sfx2/basedlgs.hxx
@@ -29,7 +29,7 @@ class SfxBindings;
 class SfxChildWindow;
 struct SfxChildWinInfo;
 class SfxItemSet;
-struct WhichRangesContainer;
+class WhichRangesContainer;
 
 class SFX2_DLLPUBLIC SfxDialogController : public weld::GenericDialogController
 {
diff --git a/include/svl/itemset.hxx b/include/svl/itemset.hxx
index f04b274ec83b..65f7076f69ab 100644
--- a/include/svl/itemset.hxx
+++ b/include/svl/itemset.hxx
@@ -87,13 +87,12 @@ class SAL_WARN_UNUSED SVL_DLLPUBLIC SfxItemSet
     const SfxItemSet* m_pParent;       ///< derivation
     sal_uInt16        m_nCount;        ///< number of items
     sal_uInt16        m_nRegister;     ///< number of items with 
NeedsSurrogateSupport
-    sal_uInt16        m_nTotalCount;   ///< number of WhichIDs, also size of 
m_ppItems array
 
     // bitfield (better packaging if a bool needs to be added)
     bool              m_bItemsFixed : 1; ///< true if this is a 
SfxItemSetFixed object, so does not *own* m_ppItems
 
     SfxPoolItem const** m_ppItems;     ///< pointer to array of items, we 
allocate and free this unless m_bItemsFixed==true
-    WhichRangesContainer m_pWhichRanges;  ///< array of Which Ranges
+    WhichRangesContainer m_aWhichRanges;  ///< array of Which Ranges
 
     // Notification-Callback mechanism for SwAttrSet in SW, functionPtr for 
callback
     std::function<void(const SfxPoolItem*, const SfxPoolItem*)> m_aCallback;
@@ -112,13 +111,13 @@ protected:
     using const_iterator = SfxPoolItem const**;
 
     const_iterator begin() const noexcept { return m_ppItems; }
-    const_iterator end() const noexcept { return begin() + m_nTotalCount; }
+    const_iterator end() const noexcept { return begin() + TotalCount(); }
 
-    bool empty() const noexcept { return 0 == m_nTotalCount; }
-    sal_Int32 size() const noexcept { return m_nTotalCount; }
+    bool empty() const noexcept { return 0 == TotalCount(); }
+    sal_Int32 size() const noexcept { return TotalCount(); }
     SfxPoolItem const* operator[](sal_Int32 idx) const noexcept
     {
-        assert(idx >= 0 && idx < m_nTotalCount && "index out of range");
+        assert(idx >= 0 && idx < TotalCount() && "index out of range");
         return m_ppItems[idx];
     }
 
@@ -141,7 +140,7 @@ protected:
     enum class SfxAllItemSetFlag { Flag };
     SfxItemSet( SfxItemPool&, SfxAllItemSetFlag );
     /** special constructor for SfxItemSetFixed */
-    SfxItemSet( SfxItemPool&, WhichRangesContainer&& ranges, SfxPoolItem const 
** ppItems, sal_uInt16 nTotalCount );
+    SfxItemSet( SfxItemPool&, WhichRangesContainer&& ranges, SfxPoolItem const 
** ppItems);
     /** special constructor for SfxItemSetFixed copy constructor */
     SfxItemSet( const SfxItemSet& rOther, SfxPoolItem const ** ppMyItems );
 
@@ -167,7 +166,7 @@ public:
 
     // Get number of items
     sal_uInt16                  Count() const { return m_nCount; }
-    sal_uInt16                  TotalCount() const { return m_nTotalCount; }
+    sal_uInt16                  TotalCount() const { return 
m_aWhichRanges.TotalCount(); }
 
     bool IsItemsFixed() const { return m_bItemsFixed; }
 
@@ -280,7 +279,7 @@ public:
     void                        MergeValue( const SfxPoolItem& rItem, bool 
bOverwriteDefaults = false  );
 
     SfxItemPool*                GetPool() const { return m_pPool; }
-    const WhichRangesContainer & GetRanges() const { return m_pWhichRanges; }
+    const WhichRangesContainer & GetRanges() const { return m_aWhichRanges; }
     void                        SetRanges( const WhichRangesContainer& );
     void                        SetRanges( WhichRangesContainer&& );
     void                        MergeRange( sal_uInt16 nFrom, sal_uInt16 nTo );
@@ -377,8 +376,7 @@ class SfxItemSetFixed : public 
SfxItemSetFixedStorage<WIDs...>, public SfxItemSe
 public:
     SfxItemSetFixed( SfxItemPool& rPool)
         : SfxItemSet(rPool, WhichRangesContainer(svl::Items_t<WIDs...>{}),
-                     SfxItemSetFixedStorage<WIDs...>::m_aItems,
-                     SfxItemSetFixedStorage<WIDs...>::NITEMS) {}
+                     SfxItemSetFixedStorage<WIDs...>::m_aItems) {}
     SfxItemSetFixed( const SfxItemSetFixed<WIDs...>& rOther )
         : SfxItemSet(rOther, SfxItemSetFixedStorage<WIDs...>::m_aItems) {}
 };
diff --git a/include/svl/whichranges.hxx b/include/svl/whichranges.hxx
index 37a3d34e5613..fa742584ebb4 100644
--- a/include/svl/whichranges.hxx
+++ b/include/svl/whichranges.hxx
@@ -77,15 +77,13 @@ template <sal_uInt16... WIDs> inline static constexpr auto 
Items = Items_t<WIDs.
  * Most of the time, the which ranges we point at are a compile-time literal.
  * So we take advantage of that, and avoid the cost of allocating our own 
array and copying into it.
  */
-struct SVL_DLLPUBLIC WhichRangesContainer
+class SVL_DLLPUBLIC WhichRangesContainer
 {
     using const_iterator = WhichPair const*;
 
     WhichPair const* m_pairs = nullptr;
     sal_Int32 m_size = 0;
-    /** if true, we allocated and need to delete the pairs, if not, we are 
pointing
-      * at a global const literal */
-    bool m_bOwnRanges = false;
+    mutable sal_uInt16 m_TotalCount = 0;
 
     // variables for buffering the last used WhichPair to allow fast answers
     // in getOffsetFromWhich
@@ -93,26 +91,57 @@ struct SVL_DLLPUBLIC WhichRangesContainer
     mutable sal_uInt16 m_aLastWhichPairFirst = 0;
     mutable sal_uInt16 m_aLastWhichPairSecond = 0;
 
+    /** if true, we allocated and need to delete the pairs, if not, we are 
pointing
+      * at a global const literal */
+    bool m_bOwnRanges = false;
+
+    /**
+     * Determines the number of sal_uInt16s in a container of pairs of
+     * sal_uInt16s, each representing a range of sal_uInt16s, and total 
capacity of the ranges.
+     */
+    void CountRanges() const;
+
+public:
+#ifdef DBG_UTIL
+    inline bool validRanges2() const
+    {
+        for (sal_Int32 i = 0; i < size(); ++i)
+        {
+            auto p = (*this)[i];
+            if (!svl::detail::validRange(p.first, p.second))
+                return false;
+            // ranges must be sorted
+            if (i < size() - 1 && !svl::detail::validGap(p.second, (*this)[i + 
1].first))
+                return false;
+        }
+        return true;
+    }
+#endif
+
     WhichRangesContainer() = default;
 
     WhichRangesContainer(std::unique_ptr<WhichPair[]> wids, sal_Int32 nSize)
         : m_pairs(wids.release())
         , m_size(nSize)
-        , m_bOwnRanges(true)
+        , m_TotalCount(0)
         , m_aLastWhichPairOffset(INVALID_WHICHPAIR_OFFSET)
         , m_aLastWhichPairFirst(0)
         , m_aLastWhichPairSecond(0)
+        , m_bOwnRanges(true)
     {
+        CountRanges();
     }
     template <sal_uInt16... WIDs>
     WhichRangesContainer(svl::Items_t<WIDs...>)
         : m_pairs(svl::Items_t<WIDs...>::value.data())
         , m_size(svl::Items_t<WIDs...>::value.size())
-        , m_bOwnRanges(false)
+        , m_TotalCount(0)
         , m_aLastWhichPairOffset(INVALID_WHICHPAIR_OFFSET)
         , m_aLastWhichPairFirst(0)
         , m_aLastWhichPairSecond(0)
+        , m_bOwnRanges(false)
     {
+        CountRanges();
     }
     WhichRangesContainer(const WhichPair* wids, sal_Int32 nSize);
     WhichRangesContainer(sal_uInt16 nWhichStart, sal_uInt16 nWhichEnd);
@@ -124,15 +153,18 @@ struct SVL_DLLPUBLIC WhichRangesContainer
     WhichRangesContainer& operator=(WhichRangesContainer const& other);
 
     bool operator==(WhichRangesContainer const& other) const;
+
     const_iterator begin() const noexcept { return m_pairs; }
     const_iterator end() const noexcept { return begin() + size(); }
     bool empty() const noexcept { return m_size == 0; }
     sal_Int32 size() const noexcept { return m_size; }
+
     WhichPair const& operator[](sal_Int32 idx) const noexcept
     {
         assert(idx >= 0 && idx < size() && "index out of range");
         return m_pairs[idx];
     }
+
     void reset();
 
     // calculate and return the offset inside the fixed SfxPoolItem
@@ -144,6 +176,8 @@ struct SVL_DLLPUBLIC WhichRangesContainer
 
     // Adds a range to which ranges, keeping the ranges in valid state 
(sorted, non-overlapping)
     SAL_WARN_UNUSED_RESULT WhichRangesContainer MergeRange(sal_uInt16 nFrom, 
sal_uInt16 nTo) const;
+
+    sal_uInt16 TotalCount() const { return m_TotalCount; }
 };
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/solenv/gdb/libreoffice/svl.py b/solenv/gdb/libreoffice/svl.py
index f82b02a7b4a3..d74238337e0c 100644
--- a/solenv/gdb/libreoffice/svl.py
+++ b/solenv/gdb/libreoffice/svl.py
@@ -25,8 +25,8 @@ class ItemSetPrinter(object):
                 % (self.value['m_pPool'], self.value['m_pParent'], whichranges)
 
     def which_ranges(self):
-        whichranges = self.value['m_pWhichRanges']['m_pairs']
-        whichranges_cnt = self.value['m_pWhichRanges']['m_size']
+        whichranges = self.value['m_aWhichRanges']['m_pairs']
+        whichranges_cnt = self.value['m_aWhichRanges']['m_size']
         whiches = []
         for index in range(whichranges_cnt):
             whiches.append((int(whichranges[index]['first']), 
int(whichranges[index]['second'])))
diff --git a/svl/source/inc/items_helper.hxx b/svl/source/inc/items_helper.hxx
deleted file mode 100644
index a86b72eab879..000000000000
--- a/svl/source/inc/items_helper.hxx
+++ /dev/null
@@ -1,60 +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/.
- *
- * This file incorporates work covered by the following license notice:
- *
- *   Licensed to the Apache Software Foundation (ASF) under one or more
- *   contributor license agreements. See the NOTICE file distributed
- *   with this work for additional information regarding copyright
- *   ownership. The ASF licenses this file to you under the Apache
- *   License, Version 2.0 (the "License"); you may not use this file
- *   except in compliance with the License. You may obtain a copy of
- *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-
-#pragma once
-
-#include <sal/config.h>
-
-#include <sal/types.h>
-#include <svl/whichranges.hxx>
-
-#include <utility>
-
-namespace svl::detail
-{
-/**
- * Determines the number of sal_uInt16s in a container of pairs of
- * sal_uInt16s, each representing a range of sal_uInt16s, and total capacity 
of the ranges.
- */
-inline sal_uInt16 CountRanges(const WhichRangesContainer& pRanges)
-{
-    sal_uInt16 nCapacity = 0;
-    for (const auto& rPair : pRanges)
-    {
-        nCapacity += rangeSize(rPair.first, rPair.second);
-    }
-    return nCapacity;
-}
-
-inline bool validRanges2(const WhichRangesContainer& pRanges)
-{
-    for (sal_Int32 i = 0; i < pRanges.size(); ++i)
-    {
-        auto p = pRanges[i];
-        if (!validRange(p.first, p.second))
-            return false;
-        // ranges must be sorted
-        if (i < pRanges.size() - 1 && !validGap(p.second, pRanges[i + 
1].first))
-            return false;
-    }
-    return true;
-}
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/svl/source/items/itemset.cxx b/svl/source/items/itemset.cxx
index 23f8a1e201ee..a3efb65fe674 100644
--- a/svl/source/items/itemset.cxx
+++ b/svl/source/items/itemset.cxx
@@ -34,7 +34,6 @@
 #include <svl/setitem.hxx>
 #include <svl/whiter.hxx>
 #include <svl/voiditem.hxx>
-#include <items_helper.hxx>
 
 static bool 
g_bDisableItemInstanceManager(getenv("SVL_DISABLE_ITEM_INSTANCE_MANAGER"));
 static bool g_bShareImmediately(getenv("SVL_SHARE_ITEMS_GLOBALLY_INSTANTLY"));
@@ -215,17 +214,16 @@ SfxItemSet::SfxItemSet(SfxItemPool& rPool)
     , m_pParent(nullptr)
     , m_nCount(0)
     , m_nRegister(0)
-    , m_nTotalCount(svl::detail::CountRanges(rPool.GetMergedIdRanges()))
     , m_bItemsFixed(false)
-    , m_ppItems(new SfxPoolItem const *[m_nTotalCount]{})
-    , m_pWhichRanges(rPool.GetMergedIdRanges())
+    , m_ppItems(new const 
SfxPoolItem*[rPool.GetMergedIdRanges().TotalCount()]{})
+    , m_aWhichRanges(rPool.GetMergedIdRanges())
     , m_aCallback()
 {
 #ifdef DBG_UTIL
     nAllocatedSfxItemSetCount++;
     nUsedSfxItemSetCount++;
 #endif
-    assert(svl::detail::validRanges2(m_pWhichRanges));
+    assert(m_aWhichRanges.validRanges2());
 }
 
 SfxItemSet::SfxItemSet( SfxItemPool& rPool, SfxAllItemSetFlag )
@@ -233,10 +231,9 @@ SfxItemSet::SfxItemSet( SfxItemPool& rPool, 
SfxAllItemSetFlag )
     , m_pParent(nullptr)
     , m_nCount(0)
     , m_nRegister(0)
-    , m_nTotalCount(0)
     , m_bItemsFixed(false)
     , m_ppItems(nullptr)
-    , m_pWhichRanges()
+    , m_aWhichRanges()
     , m_aCallback()
 {
 #ifdef DBG_UTIL
@@ -246,15 +243,14 @@ SfxItemSet::SfxItemSet( SfxItemPool& rPool, 
SfxAllItemSetFlag )
 }
 
 /** special constructor for SfxItemSetFixed */
-SfxItemSet::SfxItemSet( SfxItemPool& rPool, WhichRangesContainer&& ranges, 
SfxPoolItem const ** ppItems, sal_uInt16 nTotalCount )
+SfxItemSet::SfxItemSet( SfxItemPool& rPool, WhichRangesContainer&& ranges, 
SfxPoolItem const ** ppItems)//, sal_uInt16 nTotalCount )
     : m_pPool(&rPool)
     , m_pParent(nullptr)
     , m_nCount(0)
     , m_nRegister(0)
-    , m_nTotalCount(nTotalCount)
     , m_bItemsFixed(true)
     , m_ppItems(ppItems)
-    , m_pWhichRanges(std::move(ranges))
+    , m_aWhichRanges(std::move(ranges))
     , m_aCallback()
 {
 #ifdef DBG_UTIL
@@ -262,8 +258,8 @@ SfxItemSet::SfxItemSet( SfxItemPool& rPool, 
WhichRangesContainer&& ranges, SfxPo
     nUsedSfxItemSetCount++;
 #endif
     assert(ppItems);
-    assert(m_pWhichRanges.size() > 0);
-    assert(svl::detail::validRanges2(m_pWhichRanges));
+    assert(m_aWhichRanges.size() > 0);
+    assert(m_aWhichRanges.validRanges2());
 }
 
 /** special constructor for SfxItemSetFixed copy constructor */
@@ -273,10 +269,9 @@ SfxItemSet::SfxItemSet( const SfxItemSet& rOther,
     , m_pParent(rOther.m_pParent)
     , m_nCount(rOther.m_nCount)
     , m_nRegister(rOther.m_nRegister)
-    , m_nTotalCount(rOther.m_nTotalCount)
     , m_bItemsFixed(true)
     , m_ppItems(ppMyItems)
-    , m_pWhichRanges(rOther.m_pWhichRanges)
+    , m_aWhichRanges(rOther.m_aWhichRanges)
     , m_aCallback(rOther.m_aCallback)
 {
 #ifdef DBG_UTIL
@@ -284,8 +279,8 @@ SfxItemSet::SfxItemSet( const SfxItemSet& rOther,
     nUsedSfxItemSetCount++;
 #endif
     assert(ppMyItems);
-    assert(m_pWhichRanges.size() > 0);
-    assert(svl::detail::validRanges2(m_pWhichRanges));
+    assert(m_aWhichRanges.size() > 0);
+    assert(m_aWhichRanges.validRanges2());
 
     if (0 == rOther.Count())
         return;
@@ -308,18 +303,17 @@ SfxItemSet::SfxItemSet(SfxItemPool& pool, 
WhichRangesContainer wids)
     , m_pParent(nullptr)
     , m_nCount(0)
     , m_nRegister(0)
-    , m_nTotalCount(svl::detail::CountRanges(wids))
     , m_bItemsFixed(false)
-    , m_ppItems(new SfxPoolItem const *[m_nTotalCount]{})
-    , m_pWhichRanges(std::move(wids))
+    , m_ppItems(new const SfxPoolItem*[wids.TotalCount()]{})
+    , m_aWhichRanges(std::move(wids))
     , m_aCallback()
 {
 #ifdef DBG_UTIL
     nAllocatedSfxItemSetCount++;
     nUsedSfxItemSetCount++;
 #endif
-    assert(svl::detail::CountRanges(m_pWhichRanges) != 0);
-    assert(svl::detail::validRanges2(m_pWhichRanges));
+    assert(m_aWhichRanges.TotalCount() != 0);
+    assert(m_aWhichRanges.validRanges2());
 }
 
 // Class that implements global Item sharing. It uses rtti to
@@ -746,10 +740,9 @@ SfxItemSet::SfxItemSet( const SfxItemSet& rASet )
     , m_pParent( rASet.m_pParent )
     , m_nCount( rASet.m_nCount )
     , m_nRegister( rASet.m_nRegister )
-    , m_nTotalCount( rASet.m_nTotalCount )
     , m_bItemsFixed(false)
     , m_ppItems(nullptr)
-    , m_pWhichRanges( rASet.m_pWhichRanges )
+    , m_aWhichRanges( rASet.m_aWhichRanges )
     , m_aCallback(rASet.m_aCallback)
 {
 #ifdef DBG_UTIL
@@ -779,7 +772,7 @@ SfxItemSet::SfxItemSet( const SfxItemSet& rASet )
         ppDst++;
     }
 
-    assert(svl::detail::validRanges2(m_pWhichRanges));
+    assert(m_aWhichRanges.validRanges2());
     if (0 != m_nRegister)
         GetPool()->registerItemSet(*this);
 }
@@ -789,10 +782,9 @@ SfxItemSet::SfxItemSet(SfxItemSet&& rASet) noexcept
     , m_pParent( rASet.m_pParent )
     , m_nCount( rASet.m_nCount )
     , m_nRegister( rASet.m_nRegister )
-    , m_nTotalCount( rASet.m_nTotalCount )
     , m_bItemsFixed(false)
     , m_ppItems( rASet.m_ppItems )
-    , m_pWhichRanges( std::move(rASet.m_pWhichRanges) )
+    , m_aWhichRanges( std::move(rASet.m_aWhichRanges) )
     , m_aCallback(rASet.m_aCallback)
 {
 #ifdef DBG_UTIL
@@ -823,12 +815,11 @@ SfxItemSet::SfxItemSet(SfxItemSet&& rASet) noexcept
     rASet.m_pParent = nullptr;
     rASet.m_nCount = 0;
     rASet.m_nRegister = 0;
-    rASet.m_nTotalCount = 0;
     rASet.m_ppItems = nullptr;
-    rASet.m_pWhichRanges.reset();
+    rASet.m_aWhichRanges.reset();
     rASet.m_aCallback = nullptr;
 
-    assert(svl::detail::validRanges2(m_pWhichRanges));
+    assert(m_aWhichRanges.validRanges2());
 }
 
 SfxItemSet::~SfxItemSet()
@@ -847,7 +838,7 @@ SfxItemSet::~SfxItemSet()
     }
 
     // for invariant-testing
-    m_pWhichRanges.reset();
+    m_aWhichRanges.reset();
 }
 
 // Delete single Items or all Items (nWhich == 0)
@@ -1023,7 +1014,7 @@ void SfxItemSet::InvalidateAllItems()
     std::fill(begin(), begin() + TotalCount(), INVALID_POOL_ITEM);
 
     // ...and correct the count - invalid items get counted
-    m_nCount = m_nTotalCount;
+    m_nCount = TotalCount();
 }
 
 SfxItemState SfxItemSet::GetItemState_ForWhichID( SfxItemState eState, 
sal_uInt16 nWhich, bool bSrchInParent, const SfxPoolItem **ppItem) const
@@ -1330,41 +1321,41 @@ void SfxItemSet::MergeRange( sal_uInt16 nFrom, 
sal_uInt16 nTo )
         return;
 
     // need to create new WhichRanges
-    auto pNewRanges = m_pWhichRanges.MergeRange(nFrom, nTo);
-    RecreateRanges_Impl(pNewRanges);
-    m_pWhichRanges = std::move(pNewRanges);
+    auto aNewRanges = m_aWhichRanges.MergeRange(nFrom, nTo);
+    RecreateRanges_Impl(aNewRanges);
+    m_aWhichRanges = std::move(aNewRanges);
 }
 
 /**
  * Modifies the ranges of settable items. Keeps state of items which
  * are new ranges too.
  */
-void SfxItemSet::SetRanges( const WhichRangesContainer& pNewRanges )
+void SfxItemSet::SetRanges( const WhichRangesContainer& aNewRanges )
 {
     // Identical Ranges?
-    if (GetRanges() == pNewRanges)
+    if (GetRanges() == aNewRanges)
         return;
 
-    assert(svl::detail::validRanges2(pNewRanges));
-    RecreateRanges_Impl(pNewRanges);
-    m_pWhichRanges = pNewRanges;
+    assert(aNewRanges.validRanges2());
+    RecreateRanges_Impl(aNewRanges);
+    m_aWhichRanges = aNewRanges;
 }
 
-void SfxItemSet::SetRanges( WhichRangesContainer&& pNewRanges )
+void SfxItemSet::SetRanges( WhichRangesContainer&& aNewRanges )
 {
     // Identical Ranges?
-    if (GetRanges() == pNewRanges)
+    if (GetRanges() == aNewRanges)
         return;
 
-    assert(svl::detail::validRanges2(pNewRanges));
-    RecreateRanges_Impl(pNewRanges);
-    m_pWhichRanges = std::move(pNewRanges);
+    assert(aNewRanges.validRanges2());
+    RecreateRanges_Impl(aNewRanges);
+    m_aWhichRanges = std::move(aNewRanges);
 }
 
 void SfxItemSet::RecreateRanges_Impl(const WhichRangesContainer& rNewRanges)
 {
     // create new item-array (by iterating through all new ranges)
-    const sal_uInt16 nNewTotalCount(svl::detail::CountRanges(rNewRanges));
+    const sal_uInt16 nNewTotalCount(rNewRanges.TotalCount());
     SfxPoolItem const** aNewItemArray(new const SfxPoolItem* [nNewTotalCount]);
     sal_uInt16 nNewCount(0);
 
@@ -1427,7 +1418,6 @@ void SfxItemSet::RecreateRanges_Impl(const 
WhichRangesContainer& rNewRanges)
         delete[] m_ppItems;
     }
 
-    m_nTotalCount = nNewTotalCount;
     m_ppItems = aNewItemArray;
     m_nCount = nNewCount;
 }
@@ -2152,59 +2142,78 @@ std::unique_ptr<SfxItemSet> SfxAllItemSet::Clone(bool 
bItems, SfxItemPool *pToPo
 }
 
 
+void WhichRangesContainer::CountRanges() const
+{
+    m_TotalCount = 0;
+    for (const auto& rPair : *this)
+        m_TotalCount += svl::detail::rangeSize(rPair.first, rPair.second);
+}
+
 WhichRangesContainer::WhichRangesContainer( const WhichPair* wids, sal_Int32 
nSize )
+: m_pairs(nullptr)
+, m_size(nSize)
+, m_TotalCount(0)
+, m_aLastWhichPairOffset(INVALID_WHICHPAIR_OFFSET)
+, m_aLastWhichPairFirst(0)
+, m_aLastWhichPairSecond(0)
+, m_bOwnRanges(true)
 {
     auto p = new WhichPair[nSize];
     for (int i=0; i<nSize; ++i)
         p[i] = wids[i];
     m_pairs = p;
-    m_size = nSize;
-    m_bOwnRanges = true;
-    m_aLastWhichPairOffset = INVALID_WHICHPAIR_OFFSET;
-    m_aLastWhichPairFirst = 0;
-    m_aLastWhichPairSecond = 0;
+    CountRanges();
 }
 
 WhichRangesContainer::WhichRangesContainer(sal_uInt16 nWhichStart, sal_uInt16 
nWhichEnd)
-    : m_size(1), m_bOwnRanges(true)
+: m_pairs(nullptr)
+, m_size(1)
+, m_TotalCount(0)
+, m_aLastWhichPairOffset(INVALID_WHICHPAIR_OFFSET)
+, m_aLastWhichPairFirst(0)
+, m_aLastWhichPairSecond(0)
+, m_bOwnRanges(true)
 {
     auto p = new WhichPair[1];
     p[0] = { nWhichStart, nWhichEnd };
     m_pairs = p;
-    m_aLastWhichPairOffset = INVALID_WHICHPAIR_OFFSET;
-    m_aLastWhichPairFirst = 0;
-    m_aLastWhichPairSecond = 0;
+    CountRanges();
 }
 
 WhichRangesContainer::WhichRangesContainer(WhichRangesContainer && other)
 {
     std::swap(m_pairs, other.m_pairs);
     std::swap(m_size, other.m_size);
+    std::swap(m_TotalCount, other.m_TotalCount);
+    std::swap(m_aLastWhichPairOffset, other.m_aLastWhichPairOffset);
+    std::swap(m_aLastWhichPairFirst, other.m_aLastWhichPairFirst);
+    std::swap(m_aLastWhichPairSecond, other.m_aLastWhichPairSecond);
     std::swap(m_bOwnRanges, other.m_bOwnRanges);
-    m_aLastWhichPairOffset = INVALID_WHICHPAIR_OFFSET;
-    m_aLastWhichPairFirst = 0;
-    m_aLastWhichPairSecond = 0;
 }
 
 WhichRangesContainer& WhichRangesContainer::operator=(WhichRangesContainer && 
other)
 {
     std::swap(m_pairs, other.m_pairs);
     std::swap(m_size, other.m_size);
+    std::swap(m_TotalCount, other.m_TotalCount);
+    std::swap(m_aLastWhichPairOffset, other.m_aLastWhichPairOffset);
+    std::swap(m_aLastWhichPairFirst, other.m_aLastWhichPairFirst);
+    std::swap(m_aLastWhichPairSecond, other.m_aLastWhichPairSecond);
     std::swap(m_bOwnRanges, other.m_bOwnRanges);
-    m_aLastWhichPairOffset = INVALID_WHICHPAIR_OFFSET;
-    m_aLastWhichPairFirst = 0;
-    m_aLastWhichPairSecond = 0;
     return *this;
 }
 
 WhichRangesContainer& WhichRangesContainer::operator=(WhichRangesContainer 
const & other)
 {
     reset();
+
     m_size = other.m_size;
+    m_TotalCount = other.m_TotalCount;
+    m_aLastWhichPairOffset = other.m_aLastWhichPairOffset;
+    m_aLastWhichPairFirst = other.m_aLastWhichPairFirst;
+    m_aLastWhichPairSecond = other.m_aLastWhichPairSecond;
     m_bOwnRanges = other.m_bOwnRanges;
-    m_aLastWhichPairOffset = INVALID_WHICHPAIR_OFFSET;
-    m_aLastWhichPairFirst = 0;
-    m_aLastWhichPairSecond = 0;
+
     if (m_bOwnRanges)
     {
         auto p = new WhichPair[m_size];
@@ -2214,6 +2223,7 @@ WhichRangesContainer& 
WhichRangesContainer::operator=(WhichRangesContainer const
     }
     else
         m_pairs = other.m_pairs;
+
     return *this;
 }
 
@@ -2226,6 +2236,8 @@ bool 
WhichRangesContainer::operator==(WhichRangesContainer const & other) const
 {
     if (m_size != other.m_size)
         return false;
+    if (m_TotalCount != other.m_TotalCount)
+        return false;
     if (m_pairs == other.m_pairs)
         return true;
     return std::equal(m_pairs, m_pairs + m_size, other.m_pairs, other.m_pairs 
+ m_size);
@@ -2241,6 +2253,7 @@ void WhichRangesContainer::reset()
     }
     m_pairs = nullptr;
     m_size = 0;
+    m_TotalCount = 0;
     m_aLastWhichPairOffset = INVALID_WHICHPAIR_OFFSET;
     m_aLastWhichPairFirst = 0;
     m_aLastWhichPairSecond = 0;
diff --git a/svl/source/items/whiter.cxx b/svl/source/items/whiter.cxx
index 13915415df08..33fd59f9378d 100644
--- a/svl/source/items/whiter.cxx
+++ b/svl/source/items/whiter.cxx
@@ -22,7 +22,7 @@
 
 SfxWhichIter::SfxWhichIter(const SfxItemSet& rSet)
     : m_rItemSet(rSet)
-    , m_pCurrentWhichPair(rSet.m_pWhichRanges.begin())
+    , m_pCurrentWhichPair(rSet.m_aWhichRanges.begin())
     , m_nOffsetFromStartOfCurrentWhichPair(0)
     , m_nItemsOffset(0)
 {
@@ -30,7 +30,7 @@ SfxWhichIter::SfxWhichIter(const SfxItemSet& rSet)
 
 sal_uInt16 SfxWhichIter::GetCurWhich() const
 {
-    const WhichRangesContainer& rWhichRanges = m_rItemSet.m_pWhichRanges;
+    const WhichRangesContainer& rWhichRanges = m_rItemSet.m_aWhichRanges;
     if (m_pCurrentWhichPair >= (rWhichRanges.begin() + rWhichRanges.size()))
         return 0;
     return m_pCurrentWhichPair->first + m_nOffsetFromStartOfCurrentWhichPair;
@@ -38,7 +38,7 @@ sal_uInt16 SfxWhichIter::GetCurWhich() const
 
 sal_uInt16 SfxWhichIter::NextWhich()
 {
-    const WhichRangesContainer& rWhichRanges = m_rItemSet.m_pWhichRanges;
+    const WhichRangesContainer& rWhichRanges = m_rItemSet.m_aWhichRanges;
     if (m_pCurrentWhichPair >= (rWhichRanges.begin() + rWhichRanges.size()))
         return 0;
 
@@ -57,7 +57,7 @@ sal_uInt16 SfxWhichIter::NextWhich()
 
 sal_uInt16 SfxWhichIter::FirstWhich()
 {
-    m_pCurrentWhichPair = m_rItemSet.m_pWhichRanges.begin();
+    m_pCurrentWhichPair = m_rItemSet.m_aWhichRanges.begin();
     m_nOffsetFromStartOfCurrentWhichPair = 0;
     m_nItemsOffset = 0;
     return m_pCurrentWhichPair->first;
diff --git a/sw/source/uibase/inc/tabsh.hxx b/sw/source/uibase/inc/tabsh.hxx
index 6816376c1055..95f5d9108537 100644
--- a/sw/source/uibase/inc/tabsh.hxx
+++ b/sw/source/uibase/inc/tabsh.hxx
@@ -24,7 +24,7 @@
 
 class SfxItemSet;
 class SwWrtShell;
-struct WhichRangesContainer;
+class WhichRangesContainer;
 
 SW_DLLPUBLIC void ItemSetToTableParam( const SfxItemSet& rSet, SwWrtShell &rSh 
);
 

Reply via email to