summaryrefslogtreecommitdiff
path: root/svx/qa
diff options
context:
space:
mode:
authorNoel Grandin <noelgrandin@gmail.com>2021-07-10 10:19:28 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2021-07-15 14:41:13 +0200
commit5d0a231b29dfd4d587c7a4d1bbda6a511f94ec77 (patch)
treeebc1d470fd891fe0f9e68a002055c4d3a8dd4884 /svx/qa
parentdf9ca514d4e9ea87bbf0a96d99181ed8965cd45a (diff)
WhichRangesContainer, reduce malloc in SfxItemSet
SfxItemSet shows up in perf profiles frequently, and the hottest part is the malloc of the two arrays we need. But most of the time, one of those arrays is a compile-time constant. So this change introduces (*) WhichRangesContainer, which manages whether the SfxItemSet owns the array it points at or not. (*) a static const member in svl::Items (idea from mkaganski) to store the data. Change-Id: Icb8cdbc4d54fd76739565c575e16a744515e5355 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118703 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'svx/qa')
-rw-r--r--svx/qa/unit/removewhichrange.cxx107
1 files changed, 49 insertions, 58 deletions
diff --git a/svx/qa/unit/removewhichrange.cxx b/svx/qa/unit/removewhichrange.cxx
index fc2b0a038931..1c45e2d7874e 100644
--- a/svx/qa/unit/removewhichrange.cxx
+++ b/svx/qa/unit/removewhichrange.cxx
@@ -16,6 +16,7 @@
#include <sal/types.h>
#include <svx/svdetc.hxx>
+#include <svl/itemset.hxx>
namespace
{
@@ -28,98 +29,88 @@ class TestRemoveWhichRange : public CppUnit::TestFixture
void testRemoveWhichRange()
{
{
- sal_uInt16 const in[] = { 0 };
+ WhichRangesContainer in;
auto const out = RemoveWhichRange(in, 10, 20);
- CPPUNIT_ASSERT_EQUAL(sal_uInt16(0), out[0]);
+ CPPUNIT_ASSERT(out.empty());
}
{
- sal_uInt16 const in[] = { 10, 20, 30, 40, 0 };
+ WhichRangesContainer in(svl::Items<10, 20, 30, 40>::value);
auto const out = RemoveWhichRange(in, 0, 20);
- CPPUNIT_ASSERT_EQUAL(sal_uInt16(30), out[0]);
- CPPUNIT_ASSERT_EQUAL(sal_uInt16(40), out[1]);
- CPPUNIT_ASSERT_EQUAL(sal_uInt16(0), out[2]);
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(30), out[0].first);
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(40), out[0].second);
}
{
- sal_uInt16 const in[] = { 10, 20, 30, 40, 0 };
+ WhichRangesContainer in(svl::Items<10, 20, 30, 40>::value);
auto const out = RemoveWhichRange(in, 10, 20);
- CPPUNIT_ASSERT_EQUAL(sal_uInt16(30), out[0]);
- CPPUNIT_ASSERT_EQUAL(sal_uInt16(40), out[1]);
- CPPUNIT_ASSERT_EQUAL(sal_uInt16(0), out[2]);
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(30), out[0].first);
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(40), out[0].second);
}
{
- sal_uInt16 const in[] = { 10, 20, 30, 40, 0 };
+ WhichRangesContainer in(svl::Items<10, 20, 30, 40>::value);
auto const out = RemoveWhichRange(in, 15, 20);
- CPPUNIT_ASSERT_EQUAL(sal_uInt16(10), out[0]);
- CPPUNIT_ASSERT_EQUAL(sal_uInt16(14), out[1]);
- CPPUNIT_ASSERT_EQUAL(sal_uInt16(30), out[2]);
- CPPUNIT_ASSERT_EQUAL(sal_uInt16(40), out[3]);
- CPPUNIT_ASSERT_EQUAL(sal_uInt16(0), out[4]);
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(10), out[0].first);
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(14), out[0].second);
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(30), out[1].first);
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(40), out[1].second);
}
{
- sal_uInt16 const in[] = { 10, 20, 30, 40, 0 };
+ WhichRangesContainer in(svl::Items<10, 20, 30, 40>::value);
auto const out = RemoveWhichRange(in, 30, 40);
- CPPUNIT_ASSERT_EQUAL(sal_uInt16(10), out[0]);
- CPPUNIT_ASSERT_EQUAL(sal_uInt16(20), out[1]);
- CPPUNIT_ASSERT_EQUAL(sal_uInt16(0), out[2]);
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(10), out[0].first);
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(20), out[0].second);
}
{
- sal_uInt16 const in[] = { 10, 20, 30, 40, 0 };
+ WhichRangesContainer in(svl::Items<10, 20, 30, 40>::value);
auto const out = RemoveWhichRange(in, 30, 50);
- CPPUNIT_ASSERT_EQUAL(sal_uInt16(10), out[0]);
- CPPUNIT_ASSERT_EQUAL(sal_uInt16(20), out[1]);
- CPPUNIT_ASSERT_EQUAL(sal_uInt16(0), out[2]);
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(10), out[0].first);
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(20), out[0].second);
}
{
- sal_uInt16 const in[] = { 10, 20, 30, 40, 0 };
+ WhichRangesContainer in(svl::Items<10, 20, 30, 40>::value);
auto const out = RemoveWhichRange(in, 30, 35);
- CPPUNIT_ASSERT_EQUAL(sal_uInt16(10), out[0]);
- CPPUNIT_ASSERT_EQUAL(sal_uInt16(20), out[1]);
- CPPUNIT_ASSERT_EQUAL(sal_uInt16(36), out[2]);
- CPPUNIT_ASSERT_EQUAL(sal_uInt16(40), out[3]);
- CPPUNIT_ASSERT_EQUAL(sal_uInt16(0), out[4]);
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(10), out[0].first);
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(20), out[0].second);
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(36), out[1].first);
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(40), out[1].second);
}
{
- sal_uInt16 const in[] = { 10, 20, 30, 40, 0 };
+ WhichRangesContainer in(svl::Items<10, 20, 30, 40>::value);
auto const out = RemoveWhichRange(in, 15, 35);
- CPPUNIT_ASSERT_EQUAL(sal_uInt16(10), out[0]);
- CPPUNIT_ASSERT_EQUAL(sal_uInt16(14), out[1]);
- CPPUNIT_ASSERT_EQUAL(sal_uInt16(36), out[2]);
- CPPUNIT_ASSERT_EQUAL(sal_uInt16(40), out[3]);
- CPPUNIT_ASSERT_EQUAL(sal_uInt16(0), out[4]);
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(10), out[0].first);
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(14), out[0].second);
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(36), out[1].first);
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(40), out[1].second);
}
{
- sal_uInt16 const in[] = { 10, 20, 30, 40, 0 };
+ WhichRangesContainer in(svl::Items<10, 20, 30, 40>::value);
auto const out = RemoveWhichRange(in, 12, 15);
- CPPUNIT_ASSERT_EQUAL(sal_uInt16(10), out[0]);
- CPPUNIT_ASSERT_EQUAL(sal_uInt16(11), out[1]);
- CPPUNIT_ASSERT_EQUAL(sal_uInt16(16), out[2]);
- CPPUNIT_ASSERT_EQUAL(sal_uInt16(20), out[3]);
- CPPUNIT_ASSERT_EQUAL(sal_uInt16(30), out[4]);
- CPPUNIT_ASSERT_EQUAL(sal_uInt16(40), out[5]);
- CPPUNIT_ASSERT_EQUAL(sal_uInt16(0), out[6]);
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(10), out[0].first);
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(11), out[0].second);
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(16), out[1].first);
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(20), out[1].second);
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(30), out[2].first);
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(40), out[2].second);
}
{
- sal_uInt16 const in[] = { 10, 20, 30, 40, 0 };
+ WhichRangesContainer in(svl::Items<10, 20, 30, 40>::value);
auto const out = RemoveWhichRange(in, 0, 100);
- CPPUNIT_ASSERT_EQUAL(sal_uInt16(0), out[0]);
+ CPPUNIT_ASSERT(out.empty());
}
{
- sal_uInt16 const in[] = { 10, 20, 40, 50, 0 };
+ WhichRangesContainer in(svl::Items<10, 20, 40, 50>::value);
auto const out = RemoveWhichRange(in, 25, 35);
- CPPUNIT_ASSERT_EQUAL(sal_uInt16(10), out[0]);
- CPPUNIT_ASSERT_EQUAL(sal_uInt16(20), out[1]);
- CPPUNIT_ASSERT_EQUAL(sal_uInt16(40), out[2]);
- CPPUNIT_ASSERT_EQUAL(sal_uInt16(50), out[3]);
- CPPUNIT_ASSERT_EQUAL(sal_uInt16(0), out[4]);
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(10), out[0].first);
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(20), out[0].second);
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(40), out[1].first);
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(50), out[1].second);
}
{
- sal_uInt16 const in[] = { 10, 20, 40, 50, 0 };
+ WhichRangesContainer in(svl::Items<10, 20, 40, 50>::value);
auto const out = RemoveWhichRange(in, 50, 100);
- CPPUNIT_ASSERT_EQUAL(sal_uInt16(10), out[0]);
- CPPUNIT_ASSERT_EQUAL(sal_uInt16(20), out[1]);
- CPPUNIT_ASSERT_EQUAL(sal_uInt16(40), out[2]);
- CPPUNIT_ASSERT_EQUAL(sal_uInt16(49), out[3]);
- CPPUNIT_ASSERT_EQUAL(sal_uInt16(0), out[4]);
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(10), out[0].first);
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(20), out[0].second);
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(40), out[1].first);
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(49), out[1].second);
}
}
};