sc/inc/cellsuno.hxx              |    9 ++++++++
 sc/source/filter/xml/xmlrowi.cxx |   10 ---------
 sc/source/ui/unoobj/cellsuno.cxx |   40 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 50 insertions(+), 9 deletions(-)

New commits:
commit b00bb0e9dcde085c103d42a7e22149bd914a91a9
Author:     Noel Grandin <noelgran...@gmail.com>
AuthorDate: Sat Apr 5 21:14:58 2025 +0200
Commit:     Noel Grandin <noelgran...@gmail.com>
CommitDate: Sun Apr 6 12:29:24 2025 +0200

    tdf#151876 shave some time off chart load
    
    reduce the number of temporary UNO objects we create
    
    Change-Id: Ia429282e516610fd9ee2677bb930da9e02f6e43a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/183750
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sc/inc/cellsuno.hxx b/sc/inc/cellsuno.hxx
index fdf1c2816e1d..c3f627f0bbcd 100644
--- a/sc/inc/cellsuno.hxx
+++ b/sc/inc/cellsuno.hxx
@@ -113,6 +113,7 @@ class SfxHint;
 class SfxItemPropertyMap;
 class SfxItemPropertySet;
 struct SfxItemPropertyMapEntry;
+class ScTableRowsObj;
 
 namespace editeng { class SvxBorderLine; }
 
@@ -607,6 +608,14 @@ public:
     virtual OUString SAL_CALL getImplementationName() override;
     virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) 
override;
     virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() 
override;
+
+    rtl::Reference< ScCellRangeObj >
+                            getScCellRangeByPosition( sal_Int32 nLeft, 
sal_Int32 nTop,
+                                sal_Int32 nRight, sal_Int32 nBottom );
+    rtl::Reference< ScTableRowsObj >
+                            getScRowsByPosition( sal_Int32 nLeft, sal_Int32 
nTop,
+                                sal_Int32 nRight, sal_Int32 nBottom );
+    rtl::Reference< ScTableRowsObj > getScRows();
 };
 
 //! really derive cell from range?
diff --git a/sc/source/filter/xml/xmlrowi.cxx b/sc/source/filter/xml/xmlrowi.cxx
index a2ad7c33e703..aba21021755e 100644
--- a/sc/source/filter/xml/xmlrowi.cxx
+++ b/sc/source/filter/xml/xmlrowi.cxx
@@ -163,15 +163,7 @@ void SAL_CALL 
ScXMLTableRowContext::endFastElement(sal_Int32 /*nElement*/)
         nFirstRow = pDoc->MaxRow();
     if (nCurrentRow > pDoc->MaxRow())
         nCurrentRow = pDoc->MaxRow();
-    uno::Reference <table::XCellRange> 
xCellRange(xSheet->getCellRangeByPosition(0, nFirstRow, 0, nCurrentRow));
-    if (!xCellRange.is())
-        return;
-
-    uno::Reference<table::XColumnRowRange> xColumnRowRange (xCellRange, 
uno::UNO_QUERY);
-    if (!xColumnRowRange.is())
-        return;
-
-    uno::Reference <beans::XPropertySet> 
xRowProperties(xColumnRowRange->getRows(), uno::UNO_QUERY);
+    rtl::Reference<ScTableRowsObj> 
xRowProperties(xSheet->getScRowsByPosition(0, nFirstRow, 0, nCurrentRow));
     if (!xRowProperties.is())
         return;
 
diff --git a/sc/source/ui/unoobj/cellsuno.cxx b/sc/source/ui/unoobj/cellsuno.cxx
index 83f8953010e1..38e206502050 100644
--- a/sc/source/ui/unoobj/cellsuno.cxx
+++ b/sc/source/ui/unoobj/cellsuno.cxx
@@ -4507,6 +4507,12 @@ uno::Reference<table::XCell> SAL_CALL 
ScCellRangeObj::getCellByPosition(
 
 uno::Reference<table::XCellRange> SAL_CALL 
ScCellRangeObj::getCellRangeByPosition(
                 sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nRight, sal_Int32 
nBottom )
+{
+    return getScCellRangeByPosition(nLeft, nTop, nRight, nBottom);
+}
+
+rtl::Reference<ScCellRangeObj> ScCellRangeObj::getScCellRangeByPosition(
+                sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nRight, sal_Int32 
nBottom )
 {
     SolarMutexGuard aGuard;
 
@@ -4533,6 +4539,35 @@ uno::Reference<table::XCellRange> SAL_CALL 
ScCellRangeObj::getCellRangeByPositio
     throw lang::IndexOutOfBoundsException();
 }
 
+rtl::Reference<ScTableRowsObj> ScCellRangeObj::getScRowsByPosition(
+                sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nRight, sal_Int32 
nBottom )
+{
+    SolarMutexGuard aGuard;
+
+    ScDocShell* pDocSh = GetDocShell();
+    if (!pDocSh)
+        throw uno::RuntimeException();
+
+    if ( nLeft >= 0 && nTop >= 0 && nRight >= 0 && nBottom >= 0 )
+    {
+        sal_Int32 nStartX = aRange.aStart.Col() + nLeft;
+        sal_Int32 nStartY = aRange.aStart.Row() + nTop;
+        sal_Int32 nEndX = aRange.aStart.Col() + nRight;
+        sal_Int32 nEndY = aRange.aStart.Row() + nBottom;
+
+        if ( nStartX <= nEndX && nEndX <= aRange.aEnd.Col() &&
+             nStartY <= nEndY && nEndY <= aRange.aEnd.Row() )
+        {
+            ScRange aNew( static_cast<SCCOL>(nStartX), 
static_cast<SCROW>(nStartY), aRange.aStart.Tab(),
+                          static_cast<SCCOL>(nEndX), 
static_cast<SCROW>(nEndY), aRange.aEnd.Tab() );
+            return new ScTableRowsObj( pDocSh, aNew.aStart.Tab(),
+                                        aNew.aStart.Row(), aNew.aEnd.Row() );
+        }
+    }
+
+    throw lang::IndexOutOfBoundsException();
+}
+
 uno::Reference<table::XCellRange> SAL_CALL ScCellRangeObj::getCellRangeByName(
                         const OUString& aName )
 {
@@ -4604,6 +4639,11 @@ uno::Reference<table::XTableColumns> SAL_CALL 
ScCellRangeObj::getColumns()
 }
 
 uno::Reference<table::XTableRows> SAL_CALL ScCellRangeObj::getRows()
+{
+    return getScRows();
+}
+
+rtl::Reference<ScTableRowsObj> ScCellRangeObj::getScRows()
 {
     SolarMutexGuard aGuard;
     ScDocShell* pDocSh = GetDocShell();

Reply via email to