diff options
author | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-04-09 19:50:21 -0400 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-04-13 01:54:36 -0400 |
commit | 01944e4c8c44a7fd9a8bc42708247f1bf5a528f6 (patch) | |
tree | 7fefdb0fedb7e7e794adeb982ac96fe67e538e6f /sc | |
parent | 05f4bb6cdd5617db8db0c3d5279cff373cec949b (diff) |
Correctly implement add() and append() of shared strings interface.
Change-Id: I9c1d0e904464ff2489678972aa5c6b6e4246cd81
Diffstat (limited to 'sc')
-rw-r--r-- | sc/source/filter/inc/orcusinterface.hxx | 12 | ||||
-rw-r--r-- | sc/source/filter/orcus/interface.cxx | 33 |
2 files changed, 34 insertions, 11 deletions
diff --git a/sc/source/filter/inc/orcusinterface.hxx b/sc/source/filter/inc/orcusinterface.hxx index 313331c90abb..de07b75dca41 100644 --- a/sc/source/filter/inc/orcusinterface.hxx +++ b/sc/source/filter/inc/orcusinterface.hxx @@ -16,6 +16,7 @@ #include <orcus/spreadsheet/import_interface.hpp> #include <boost/ptr_container/ptr_vector.hpp> +#include <boost/unordered_map.hpp> #include <map> @@ -26,10 +27,10 @@ class ScRangeData; class ScOrcusSharedStrings : public orcus::spreadsheet::iface::import_shared_strings { - std::vector<OUString>& mrStrings; + ScOrcusFactory& mrFactory; public: - ScOrcusSharedStrings(std::vector<OUString>& rStrings); + ScOrcusSharedStrings(ScOrcusFactory& rFactory); virtual size_t append(const char* s, size_t n); virtual size_t add(const char* s, size_t n); @@ -161,10 +162,14 @@ class ScOrcusFactory : public orcus::spreadsheet::iface::import_factory StringCellCache(const ScAddress& rPos, size_t nIndex); }; + typedef boost::unordered_map<OUString, size_t, OUStringHash> StringHashType; typedef std::vector<StringCellCache> StringCellCaches; ScDocument& mrDoc; + std::vector<OUString> maStrings; + StringHashType maStringHash; + StringCellCaches maStringCells; ScOrcusSharedStrings maSharedStrings; boost::ptr_vector<ScOrcusSheet> maSheets; @@ -179,6 +184,9 @@ public: virtual orcus::spreadsheet::iface::import_styles* get_styles(); virtual void finalize(); + size_t appendString(const OUString& rStr); + size_t addString(const OUString& rStr); + void pushStringCell(const ScAddress& rPos, size_t nStrIndex); }; diff --git a/sc/source/filter/orcus/interface.cxx b/sc/source/filter/orcus/interface.cxx index 45f23049cef2..73b4d0beb416 100644 --- a/sc/source/filter/orcus/interface.cxx +++ b/sc/source/filter/orcus/interface.cxx @@ -24,7 +24,7 @@ using orcus::spreadsheet::formula_grammar_t; ScOrcusFactory::StringCellCache::StringCellCache(const ScAddress& rPos, size_t nIndex) : maPos(rPos), mnIndex(nIndex) {} -ScOrcusFactory::ScOrcusFactory(ScDocument& rDoc) : mrDoc(rDoc), maSharedStrings(maStrings) {} +ScOrcusFactory::ScOrcusFactory(ScDocument& rDoc) : mrDoc(rDoc), maSharedStrings(*this) {} orcus::spreadsheet::iface::import_sheet* ScOrcusFactory::append_sheet(const char* sheet_name, size_t sheet_name_length) { @@ -95,6 +95,25 @@ void ScOrcusFactory::finalize() } } +size_t ScOrcusFactory::appendString(const OUString& rStr) +{ + size_t nPos = maStrings.size(); + maStrings.push_back(rStr); + maStringHash.insert(StringHashType::value_type(rStr, nPos)); + + return nPos; +} + +size_t ScOrcusFactory::addString(const OUString& rStr) +{ + // Add only if the string is not yet present in the string pool. + StringHashType::iterator it = maStringHash.find(rStr); + if (it != maStringHash.end()) + return it->second; + + return appendString(rStr); +} + void ScOrcusFactory::pushStringCell(const ScAddress& rPos, size_t nStrIndex) { maStringCells.push_back(StringCellCache(rPos, nStrIndex)); @@ -241,23 +260,19 @@ void ScOrcusSheet::set_bool(row_t row, col_t col, bool value) mrDoc.SetValue(col, row, mnTab, value ? 1.0 : 0.0); } -ScOrcusSharedStrings::ScOrcusSharedStrings(std::vector<OUString>& rStrings) : - mrStrings(rStrings) {} +ScOrcusSharedStrings::ScOrcusSharedStrings(ScOrcusFactory& rFactory) : + mrFactory(rFactory) {} size_t ScOrcusSharedStrings::append(const char* s, size_t n) { OUString aNewString(s, n, RTL_TEXTENCODING_UTF8); - mrStrings.push_back(aNewString); - - return mrStrings.size() - 1; + return mrFactory.appendString(aNewString); } size_t ScOrcusSharedStrings::add(const char* s, size_t n) { OUString aNewString(s, n, RTL_TEXTENCODING_UTF8); - mrStrings.push_back(aNewString); - - return mrStrings.size() - 1; + return mrFactory.addString(aNewString); } void ScOrcusSharedStrings::set_segment_bold(bool /*b*/) |