diff options
author | Kohei Yoshida <kyoshida@novell.com> | 2010-12-01 01:25:06 -0500 |
---|---|---|
committer | Kohei Yoshida <kyoshida@novell.com> | 2010-12-02 16:06:51 -0500 |
commit | 83ebe9699eb77cdd9cb61d43041435f364cb7be1 (patch) | |
tree | d868c5febed4f02c61f8e88c0d2d2b5418ef3f2f /sc/source | |
parent | 8ad4dae2cef16c1525b5296c71626a5f4c45e68e (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')
-rw-r--r-- | sc/source/filter/xml/XMLStylesExportHelper.cxx | 22 | ||||
-rw-r--r-- | sc/source/filter/xml/XMLStylesExportHelper.hxx | 11 |
2 files changed, 32 insertions, 1 deletions
diff --git a/sc/source/filter/xml/XMLStylesExportHelper.cxx b/sc/source/filter/xml/XMLStylesExportHelper.cxx index c551fb4c3..5120ac27c 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; } diff --git a/sc/source/filter/xml/XMLStylesExportHelper.hxx b/sc/source/filter/xml/XMLStylesExportHelper.hxx index 58243827c..368ec4453 100644 --- a/sc/source/filter/xml/XMLStylesExportHelper.hxx +++ b/sc/source/filter/xml/XMLStylesExportHelper.hxx @@ -277,6 +277,17 @@ class ScRowStyles : public ScColumnRowStylesBase { typedef ::mdds::flat_segment_tree<sal_Int32, sal_Int32> StylesType; ::boost::ptr_vector<StylesType> aTables; + struct Cache + { + sal_Int32 mnTable; + sal_Int32 mnStart; + sal_Int32 mnEnd; + sal_Int32 mnStyle; + Cache(); + + bool hasCache(sal_Int32 nTable, sal_Int32 nField) const; + }; + Cache maCache; public: ScRowStyles(); |