diff options
author | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-02-08 21:17:54 -0500 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-02-11 22:33:33 -0500 |
commit | 7b42be6cf4f6888ed23285e1c9f2b9c7deb261c3 (patch) | |
tree | 90ec525e7357b8720338ea22e3ca62551f9b97cf | |
parent | 18588a6168ac96af8a9df60b7df746261e289061 (diff) |
Use hash map to avoid repetitious string comparisons.
Change-Id: I374f5393bf714752037e9cf416fea9667bb80e71
-rw-r--r-- | sc/Library_sc.mk | 1 | ||||
-rw-r--r-- | sc/source/filter/xml/editattributemap.cxx | 57 | ||||
-rw-r--r-- | sc/source/filter/xml/editattributemap.hxx | 43 | ||||
-rw-r--r-- | sc/source/filter/xml/importcontext.hxx | 4 | ||||
-rw-r--r-- | sc/source/filter/xml/xmlcelli.cxx | 101 | ||||
-rw-r--r-- | sc/source/filter/xml/xmlimprt.cxx | 8 | ||||
-rw-r--r-- | sc/source/filter/xml/xmlimprt.hxx | 3 |
7 files changed, 157 insertions, 60 deletions
diff --git a/sc/Library_sc.mk b/sc/Library_sc.mk index a0d4bf83f66e..d205b4a6bb1a 100644 --- a/sc/Library_sc.mk +++ b/sc/Library_sc.mk @@ -269,6 +269,7 @@ $(eval $(call gb_Library_add_exception_objects,sc,\ sc/source/filter/xml/XMLTrackedChangesContext \ sc/source/filter/xml/cachedattraccess \ sc/source/filter/xml/celltextparacontext \ + sc/source/filter/xml/editattributemap \ sc/source/filter/xml/importcontext \ sc/source/filter/xml/sheetdata \ sc/source/filter/xml/xmlannoi \ diff --git a/sc/source/filter/xml/editattributemap.cxx b/sc/source/filter/xml/editattributemap.cxx new file mode 100644 index 000000000000..3580cc026e37 --- /dev/null +++ b/sc/source/filter/xml/editattributemap.cxx @@ -0,0 +1,57 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "editattributemap.hxx" + +#include "editeng/eeitem.hxx" +#include "editeng/memberids.hrc" + +namespace { + +struct { + const char* mpXMLName; + sal_uInt16 mnItemID; + sal_uInt8 mnFlag; +} Entries[] = { + { "color", EE_CHAR_COLOR, 0 }, + { "font-weight", EE_CHAR_WEIGHT, MID_WEIGHT }, + { "font-weight-asian", EE_CHAR_WEIGHT_CJK, MID_WEIGHT }, + { "font-weight-complex", EE_CHAR_WEIGHT_CTL, MID_WEIGHT }, + { "font-size", EE_CHAR_FONTHEIGHT, MID_FONTHEIGHT }, + { "font-size-asian", EE_CHAR_FONTHEIGHT_CJK, MID_FONTHEIGHT }, + { "font-size-complex", EE_CHAR_FONTHEIGHT_CTL, MID_FONTHEIGHT }, + { "font-style", EE_CHAR_ITALIC, MID_POSTURE }, + { "font-style-asian", EE_CHAR_ITALIC_CJK, MID_POSTURE }, + { "font-style-complex", EE_CHAR_ITALIC_CTL, MID_POSTURE }, +}; + +} + +ScXMLEditAttributeMap::Entry::Entry(sal_uInt16 nItemID, sal_uInt8 nFlag) : + mnItemID(nItemID), mnFlag(nFlag) {} + +ScXMLEditAttributeMap::ScXMLEditAttributeMap() +{ + size_t n = sizeof(Entries) / sizeof(Entries[0]); + for (size_t i = 0; i < n; ++i) + { + maEntries.insert( + EntriesType::value_type( + OUString::createFromAscii(Entries[i].mpXMLName), + Entry(Entries[i].mnItemID, Entries[i].mnFlag))); + } +} + +const ScXMLEditAttributeMap::Entry* ScXMLEditAttributeMap::getEntry(const OUString& rXMLName) const +{ + EntriesType::const_iterator it = maEntries.find(rXMLName); + return it == maEntries.end() ? NULL : &it->second; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/filter/xml/editattributemap.hxx b/sc/source/filter/xml/editattributemap.hxx new file mode 100644 index 000000000000..fb981df8af0e --- /dev/null +++ b/sc/source/filter/xml/editattributemap.hxx @@ -0,0 +1,43 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef __SC_XML_EDITATTRIBUTEMAP_HXX__ +#define __SC_XML_EDITATTRIBUTEMAP_HXX__ + +#include "rtl/ustring.hxx" + +#include <boost/unordered_map.hpp> + +/** + * Provide mapping from ODF text formatting styles to EditEngine's, for + * rich-text cell content import. + */ +class ScXMLEditAttributeMap +{ +public: + struct Entry + { + sal_uInt16 mnItemID; + sal_uInt8 mnFlag; + + Entry(sal_uInt16 nItemID, sal_uInt8 nFlag); + }; + + ScXMLEditAttributeMap(); + + const Entry* getEntry(const OUString& rXMLName) const; + +private: + typedef boost::unordered_map<OUString, Entry, OUStringHash> EntriesType; + EntriesType maEntries; +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/filter/xml/importcontext.hxx b/sc/source/filter/xml/importcontext.hxx index 146e7e88a992..878bb970484e 100644 --- a/sc/source/filter/xml/importcontext.hxx +++ b/sc/source/filter/xml/importcontext.hxx @@ -7,8 +7,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef __IMPORTCONTEXT_HXX__ -#define __IMPORTCONTEXT_HXX__ +#ifndef __SC_XML_IMPORTCONTEXT_HXX__ +#define __SC_XML_IMPORTCONTEXT_HXX__ #include "xmloff/xmlictxt.hxx" #include "xmloff/xmlimp.hxx" diff --git a/sc/source/filter/xml/xmlcelli.cxx b/sc/source/filter/xml/xmlcelli.cxx index b7206abc0580..cba7fdbba703 100644 --- a/sc/source/filter/xml/xmlcelli.cxx +++ b/sc/source/filter/xml/xmlcelli.cxx @@ -47,6 +47,7 @@ #include "scerrors.hxx" #include "editutil.hxx" #include "cell.hxx" +#include "editattributemap.hxx" #include <xmloff/xmltkmap.hxx> #include <xmloff/xmltoken.hxx> @@ -339,6 +340,8 @@ void ScXMLTableRowCellContext::PushParagraphSpan(const OUString& rSpan, const OU if (rProps.empty()) return; + const ScXMLEditAttributeMap& rEditAttrMap = GetScImport().GetEditAttributeMap(); + maFormats.push_back(new ParaFormat(*mpEditEngine)); ParaFormat& rFmt = maFormats.back(); rFmt.maSelection.nStartPara = rFmt.maSelection.nEndPara = mnCurParagraph; @@ -352,66 +355,48 @@ void ScXMLTableRowCellContext::PushParagraphSpan(const OUString& rSpan, const OU continue; const OUString& rName = xMapper->GetEntryXMLName(it->mnIndex); + const ScXMLEditAttributeMap::Entry* pEntry = rEditAttrMap.getEntry(rName); + if (!pEntry) + continue; - if (rName == "font-weight") - { - SvxWeightItem aItem(WEIGHT_NORMAL, EE_CHAR_WEIGHT); - aItem.PutValue(it->maValue, MID_WEIGHT); - rFmt.maItemSet.Put(aItem); - } - else if (rName == "font-weight-asian") - { - SvxWeightItem aItem(WEIGHT_NORMAL, EE_CHAR_WEIGHT_CJK); - aItem.PutValue(it->maValue, MID_WEIGHT); - rFmt.maItemSet.Put(aItem); - } - else if (rName == "font-weight-complex") - { - SvxWeightItem aItem(WEIGHT_NORMAL, EE_CHAR_WEIGHT_CTL); - aItem.PutValue(it->maValue, MID_WEIGHT); - rFmt.maItemSet.Put(aItem); - } - else if (rName == "font-size") - { - SvxFontHeightItem aItem(240, 100, EE_CHAR_FONTHEIGHT); - aItem.PutValue(it->maValue, MID_FONTHEIGHT); - rFmt.maItemSet.Put(aItem); - } - else if (rName == "font-size-asian") - { - SvxFontHeightItem aItem(240, 100, EE_CHAR_FONTHEIGHT_CJK); - aItem.PutValue(it->maValue, MID_FONTHEIGHT); - rFmt.maItemSet.Put(aItem); - } - else if (rName == "font-size-complex") - { - SvxFontHeightItem aItem(240, 100, EE_CHAR_FONTHEIGHT_CTL); - aItem.PutValue(it->maValue, MID_FONTHEIGHT); - rFmt.maItemSet.Put(aItem); - } - else if (rName == "font-style") - { - SvxPostureItem aItem(ITALIC_NONE, EE_CHAR_ITALIC); - aItem.PutValue(it->maValue, MID_POSTURE); - rFmt.maItemSet.Put(aItem); - } - else if (rName == "font-style-asian") - { - SvxPostureItem aItem(ITALIC_NONE, EE_CHAR_ITALIC_CJK); - aItem.PutValue(it->maValue, MID_POSTURE); - rFmt.maItemSet.Put(aItem); - } - else if (rName == "font-style-complex") - { - SvxPostureItem aItem(ITALIC_NONE, EE_CHAR_ITALIC_CTL); - aItem.PutValue(it->maValue, MID_POSTURE); - rFmt.maItemSet.Put(aItem); - } - else if (rName == "color") + switch (pEntry->mnItemID) { - SvxColorItem aItem(EE_CHAR_COLOR); - aItem.PutValue(it->maValue, 0); - rFmt.maItemSet.Put(aItem); + case EE_CHAR_WEIGHT: + case EE_CHAR_WEIGHT_CJK: + case EE_CHAR_WEIGHT_CTL: + { + SvxWeightItem aItem(WEIGHT_NORMAL, pEntry->mnItemID); + aItem.PutValue(it->maValue, pEntry->mnFlag); + rFmt.maItemSet.Put(aItem); + } + break; + case EE_CHAR_FONTHEIGHT: + case EE_CHAR_FONTHEIGHT_CJK: + case EE_CHAR_FONTHEIGHT_CTL: + { + SvxFontHeightItem aItem(240, 100, pEntry->mnItemID); + aItem.PutValue(it->maValue, pEntry->mnFlag); + rFmt.maItemSet.Put(aItem); + } + break; + case EE_CHAR_ITALIC: + case EE_CHAR_ITALIC_CJK: + case EE_CHAR_ITALIC_CTL: + { + SvxPostureItem aItem(ITALIC_NONE, pEntry->mnItemID); + aItem.PutValue(it->maValue, pEntry->mnFlag); + rFmt.maItemSet.Put(aItem); + } + break; + case EE_CHAR_COLOR: + { + SvxColorItem aItem(pEntry->mnItemID); + aItem.PutValue(it->maValue, pEntry->mnFlag); + rFmt.maItemSet.Put(aItem); + } + break; + default: + ; } } } diff --git a/sc/source/filter/xml/xmlimprt.cxx b/sc/source/filter/xml/xmlimprt.cxx index c4a5ff21a3c6..0781667e8ad4 100644 --- a/sc/source/filter/xml/xmlimprt.cxx +++ b/sc/source/filter/xml/xmlimprt.cxx @@ -65,6 +65,7 @@ #include "formulaparserpool.hxx" #include "externalrefmgr.hxx" #include "editutil.hxx" +#include "editattributemap.hxx" #include <comphelper/extract.hxx> @@ -3375,4 +3376,11 @@ ScEditEngineDefaulter* ScXMLImport::GetEditEngine() return mpEditEngine.get(); } +const ScXMLEditAttributeMap& ScXMLImport::GetEditAttributeMap() const +{ + if (!mpEditAttrMap) + mpEditAttrMap.reset(new ScXMLEditAttributeMap); + return *mpEditAttrMap; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/filter/xml/xmlimprt.hxx b/sc/source/filter/xml/xmlimprt.hxx index fc5ed7a867c4..1aae0b1af012 100644 --- a/sc/source/filter/xml/xmlimprt.hxx +++ b/sc/source/filter/xml/xmlimprt.hxx @@ -758,6 +758,7 @@ struct ScMyImportValidation typedef std::vector<ScMyImportValidation> ScMyImportValidations; typedef std::list<SvXMLImportContext*> ScMyViewContextList; class ScMyStylesImportHelper; +class ScXMLEditAttributeMap; class ScXMLImport: public SvXMLImport, boost::noncopyable { @@ -769,6 +770,7 @@ class ScXMLImport: public SvXMLImport, boost::noncopyable ScDocument* pDoc; boost::scoped_ptr<ScCompiler> mpComp; // For error-checking of cached string cell values. boost::scoped_ptr<ScEditEngineDefaulter> mpEditEngine; + mutable boost::scoped_ptr<ScXMLEditAttributeMap> mpEditAttrMap; ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper; ScMyViewContextList aViewContextList; ScMyStylesImportHelper* pStylesImportHelper; @@ -1180,6 +1182,7 @@ public: bool IsFormulaErrorConstant( const OUString& rStr ) const; ScEditEngineDefaulter* GetEditEngine(); + const ScXMLEditAttributeMap& GetEditAttributeMap() const; }; #endif |