summaryrefslogtreecommitdiff
path: root/sc/source/filter/xml/XMLStylesExportHelper.cxx
diff options
context:
space:
mode:
authorKohei Yoshida <kyoshida@novell.com>2010-12-01 01:25:06 -0500
committerKohei Yoshida <kyoshida@novell.com>2010-12-02 16:06:51 -0500
commite18c9eec80bdf11c698a915392c18414707d0b1a (patch)
tree8c8c6ba0abe59528bc9f7ee52c1d9282650123b8 /sc/source/filter/xml/XMLStylesExportHelper.cxx
parentcf687f01ebcf5123c087c70a78b556893badd8ab (diff)
Cache field style index for current range for better performance.
This cuts about 3 seconds off with my test document.
Diffstat (limited to 'sc/source/filter/xml/XMLStylesExportHelper.cxx')
-rw-r--r--sc/source/filter/xml/XMLStylesExportHelper.cxx22
1 files changed, 21 insertions, 1 deletions
diff --git a/sc/source/filter/xml/XMLStylesExportHelper.cxx b/sc/source/filter/xml/XMLStylesExportHelper.cxx
index 144e6b5f7346..d01b08b99d01 100644
--- a/sc/source/filter/xml/XMLStylesExportHelper.cxx
+++ b/sc/source/filter/xml/XMLStylesExportHelper.cxx
@@ -1203,6 +1203,14 @@ rtl::OUString* ScColumnStyles::GetStyleName(const sal_Int32 nTable, const sal_In
//===========================================================================
+ScRowStyles::Cache::Cache() :
+ mnTable(-1), mnStart(-1), mnEnd(-1), mnStyle(-1) {}
+
+bool ScRowStyles::Cache::hasCache(sal_Int32 nTable, sal_Int32 nField) const
+{
+ return mnTable == nTable && mnStart <= nField && nField <= mnEnd;
+}
+
ScRowStyles::ScRowStyles()
: ScColumnRowStylesBase()
{
@@ -1225,12 +1233,24 @@ void ScRowStyles::AddNewTable(const sal_Int32 nTable, const sal_Int32 nFields)
sal_Int32 ScRowStyles::GetStyleNameIndex(const sal_Int32 nTable, const sal_Int32 nField)
{
DBG_ASSERT(static_cast<size_t>(nTable) < aTables.size(), "wrong table");
+ if (maCache.hasCache(nTable, nField))
+ // Cache hit !
+ return maCache.mnStyle;
+
StylesType& r = aTables[nTable];
if (!r.is_tree_valid())
r.build_tree();
sal_Int32 nStyle;
- if (r.search_tree(nField, nStyle))
+ sal_Int32 nStart, nEnd;
+ if (r.search_tree(nField, nStyle, &nStart, &nEnd))
+ {
+ // Cache this value for better performance.
+ maCache.mnTable = nTable;
+ maCache.mnStart = nStart;
+ maCache.mnEnd = nEnd;
+ maCache.mnStyle = nStyle;
return nStyle;
+ }
return -1;
}