summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2014-08-17 20:49:49 +0200
committerMichael Stahl <mstahl@redhat.com>2014-08-20 16:40:10 +0200
commit3426685cc2b45cd795975572ae6cbfa58658bab7 (patch)
treeb7cb0e1269cada1675f3fdefac0d4133d2fd5a81 /sw
parent37ea2c99b9374f956d2a73bf1c085f2b47d53add (diff)
i#105557: thread-safe caching of SwXTextTable instances
Add factory function SwXTextTable::CreateXTextTable that uses the WeakReference SwFrmFmt::m_wXObject to cache the instance in a thread-safe way. Change-Id: I88939e2586d104193184eea43b466f2cbeb71d6f
Diffstat (limited to 'sw')
-rw-r--r--sw/inc/unocoll.hxx2
-rw-r--r--sw/inc/unotbl.hxx5
-rw-r--r--sw/source/core/unocore/unocoll.cxx10
-rw-r--r--sw/source/core/unocore/unoobj2.cxx5
-rw-r--r--sw/source/core/unocore/unotbl.cxx21
-rw-r--r--sw/source/core/unocore/unotext.cxx12
6 files changed, 37 insertions, 18 deletions
diff --git a/sw/inc/unocoll.hxx b/sw/inc/unocoll.hxx
index 5c4caef407a9..eb55c8116f84 100644
--- a/sw/inc/unocoll.hxx
+++ b/sw/inc/unocoll.hxx
@@ -295,7 +295,7 @@ public:
virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames(void) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
- static ::com::sun::star::text::XTextTable* GetObject( SwFrmFmt& rFmt );
+ static css::uno::Reference<css::text::XTextTable> GetObject(SwFrmFmt& rFmt);
};
typedef
diff --git a/sw/inc/unotbl.hxx b/sw/inc/unotbl.hxx
index 85691bb7f517..8e10ddc46412 100644
--- a/sw/inc/unotbl.hxx
+++ b/sw/inc/unotbl.hxx
@@ -320,10 +320,13 @@ private:
bool bFirstColumnAsLabel :1;
protected:
virtual ~SwXTextTable();
-public:
SwXTextTable();
SwXTextTable(SwFrmFmt& rFrmFmt);
+public:
+ static css::uno::Reference<css::text::XTextTable>
+ CreateXTextTable(SwFrmFmt * pFrmFmt);
+
SW_DLLPUBLIC static const ::com::sun::star::uno::Sequence< sal_Int8 > & getUnoTunnelId();
//XUnoTunnel
diff --git a/sw/source/core/unocore/unocoll.cxx b/sw/source/core/unocore/unocoll.cxx
index 6bda581aa904..4bc8e8fc7aed 100644
--- a/sw/source/core/unocore/unocoll.cxx
+++ b/sw/source/core/unocore/unocoll.cxx
@@ -525,8 +525,7 @@ uno::Reference< uno::XInterface > SwXServiceProvider::MakeInstance(sal_uInt16
{
case SW_SERVICE_TYPE_TEXTTABLE:
{
- SwXTextTable* pTextTable = new SwXTextTable();
- xRet = (cppu::OWeakObject*)pTextTable;
+ xRet = SwXTextTable::CreateXTextTable(0);
}
break;
case SW_SERVICE_TYPE_TEXTFRAME:
@@ -981,13 +980,10 @@ uno::Sequence< OUString > SwXTextTables::getSupportedServiceNames(void) throw( u
return aRet;
}
-XTextTable* SwXTextTables::GetObject( SwFrmFmt& rFmt )
+uno::Reference<text::XTextTable> SwXTextTables::GetObject(SwFrmFmt& rFmt)
{
SolarMutexGuard aGuard;
- SwXTextTable* pTbl = SwIterator<SwXTextTable,SwFmt>::FirstElement( rFmt );
- if( !pTbl )
- pTbl = new SwXTextTable(rFmt);
- return pTbl ;
+ return SwXTextTable::CreateXTextTable(& rFmt);
}
namespace
diff --git a/sw/source/core/unocore/unoobj2.cxx b/sw/source/core/unocore/unoobj2.cxx
index b5a37c5ae29a..95ff2c6521e9 100644
--- a/sw/source/core/unocore/unoobj2.cxx
+++ b/sw/source/core/unocore/unoobj2.cxx
@@ -664,10 +664,7 @@ throw (container::NoSuchElementException, lang::WrappedTargetException,
// this is a foreign table
SwFrmFmt* pTableFmt =
static_cast<SwFrmFmt*>(pTblNode->GetTable().GetFrmFmt());
- text::XTextTable *const pTable =
- SwXTextTables::GetObject( *pTableFmt );
- xRef = static_cast<text::XTextContent*>(
- static_cast<SwXTextTable*>(pTable));
+ xRef = SwXTextTable::CreateXTextTable(pTableFmt);
}
else
{
diff --git a/sw/source/core/unocore/unotbl.cxx b/sw/source/core/unocore/unotbl.cxx
index b5a3fcfdebd5..70a76290aba5 100644
--- a/sw/source/core/unocore/unotbl.cxx
+++ b/sw/source/core/unocore/unotbl.cxx
@@ -2220,6 +2220,27 @@ SwXTextTable::~SwXTextTable()
delete pTableProps;
}
+uno::Reference<text::XTextTable>
+SwXTextTable::CreateXTextTable(SwFrmFmt *const pFrmFmt)
+{
+ uno::Reference<text::XTextTable> xTable;
+ if (pFrmFmt)
+ {
+ xTable.set(pFrmFmt->GetXObject(), uno::UNO_QUERY); // cached?
+ }
+ if (!xTable.is())
+ {
+ SwXTextTable *const pNew(
+ (pFrmFmt) ? new SwXTextTable(*pFrmFmt) : new SwXTextTable());
+ xTable.set(pNew);
+ if (pFrmFmt)
+ {
+ pFrmFmt->SetXObject(xTable);
+ }
+ }
+ return xTable;
+}
+
void SwXTextTable::initialize(sal_Int32 nR, sal_Int32 nC) throw( uno::RuntimeException, std::exception )
{
if(!bIsDescriptor || nR <= 0 || nC <= 0 || nR >= USHRT_MAX || nC >= USHRT_MAX )
diff --git a/sw/source/core/unocore/unotext.cxx b/sw/source/core/unocore/unotext.cxx
index b901ab2f0bc6..85feda295fd8 100644
--- a/sw/source/core/unocore/unotext.cxx
+++ b/sw/source/core/unocore/unotext.cxx
@@ -2252,9 +2252,9 @@ throw (lang::IllegalArgumentException, uno::RuntimeException, std::exception)
if (!pTable)
return uno::Reference< text::XTextTable >();
- SwXTextTable *const pTextTable = new SwXTextTable( *pTable->GetFrmFmt() );
- const uno::Reference< text::XTextTable > xRet = pTextTable;
- const uno::Reference< beans::XPropertySet > xPrSet = pTextTable;
+ uno::Reference<text::XTextTable> const xRet =
+ SwXTextTable::CreateXTextTable(pTable->GetFrmFmt());
+ uno::Reference<beans::XPropertySet> const xPrSet(xRet, uno::UNO_QUERY);
// set properties to the table
// catch lang::WrappedTargetException and lang::IndexOutOfBoundsException
try
@@ -2296,6 +2296,7 @@ throw (lang::IllegalArgumentException, uno::RuntimeException, std::exception)
lcl_DebugCellProperties(rCellProperties);
#endif
+ uno::Reference<table::XCellRange> const xCR(xRet, uno::UNO_QUERY_THROW);
//apply cell properties
for (sal_Int32 nRow = 0; nRow < rCellProperties.getLength(); ++nRow)
{
@@ -2306,7 +2307,7 @@ throw (lang::IllegalArgumentException, uno::RuntimeException, std::exception)
{
lcl_ApplyCellProperties(nCell,
aRowSeparators[nRow], aCurrentRow[nCell],
- pTextTable->getCellByPosition(nCell, nRow),
+ xCR->getCellByPosition(nCell, nRow),
aMergedCells);
}
}
@@ -2322,7 +2323,8 @@ throw (lang::IllegalArgumentException, uno::RuntimeException, std::exception)
}
assert(SwTable::FindTable(pTable->GetFrmFmt()) == pTable);
- assert(pTable->GetFrmFmt() == pTextTable->GetFrmFmt());
+ assert(pTable->GetFrmFmt() ==
+ dynamic_cast<SwXTextTable*>(xRet.get())->GetFrmFmt());
return xRet;
}