writerfilter/CustomTarget_source.mk | 5 -- writerfilter/source/ooxml/OOXMLFactory.cxx | 16 ------- writerfilter/source/ooxml/OOXMLFactory.hxx | 10 +--- writerfilter/source/ooxml/factory_ns.py | 2 writerfilter/source/ooxml/factory_values.py | 59 ---------------------------- writerfilter/source/ooxml/factoryimpl_ns.py | 27 +++++------- 6 files changed, 18 insertions(+), 101 deletions(-)
New commits: commit 7aa7047eb48e81bc0b32448ff0487c993fe9a4db Author: Jan Holesovsky <ke...@collabora.com> Date: Sun Aug 3 00:56:26 2014 +0200 writerfilter: Kill ListValueMap(s) & their construction. ListValueMaps were completely useless; it is always just few values that used to be in the unordered_map, so doing just a normal comparison couldn't be too much worse than all the hash construction etc. This saves >300k of the libwriterfilter.so size (striped). If this proves to be less performing than what we used to have (which I doubt), now when we generate the code using Python, it would be a piece of cake to construct some deterministic finite automaton in each switch's case to accept the value names, and return the values. Change-Id: I95d0470b73ade1fbf5c9de2299c4adcc59286bc3 diff --git a/writerfilter/CustomTarget_source.mk b/writerfilter/CustomTarget_source.mk index 6ff9c09..10d74a7 100644 --- a/writerfilter/CustomTarget_source.mk +++ b/writerfilter/CustomTarget_source.mk @@ -68,7 +68,6 @@ writerfilter_GEN_ooxml_NamespaceIds_hxx=$(writerfilter_WORK)/ooxml/OOXMLnamespac writerfilter_GEN_ooxml_QNameToStr_cxx=$(writerfilter_WORK)/ooxml/qnametostr.cxx writerfilter_GEN_ooxml_ResourceIds_hxx=$(writerfilter_WORK)/ooxml/resourceids.hxx writerfilter_GEN_ooxml_Token_xml=$(writerfilter_WORK)/ooxml/token.xml -writerfilter_SRC_ooxml_FactoryValues_py=$(writerfilter_SRC)/ooxml/factory_values.py writerfilter_SRC_ooxml_FastTokens_py=$(writerfilter_SRC)/ooxml/fasttokens.py writerfilter_SRC_ooxml_GperfFastTokenHandler_py=$(writerfilter_SRC)/ooxml/gperffasttokenhandler.py writerfilter_SRC_ooxml_Model=$(writerfilter_SRC)/ooxml/model.xml @@ -84,10 +83,6 @@ $(writerfilter_GEN_ooxml_Factory_hxx) : $(writerfilter_SRC)/ooxml/factoryinc.py $(call gb_Output_announce,$(subst $(WORKDIR)/,,$@),build,PY ,1) $(call gb_Helper_abbreviate_dirs, $(writerfilter_PYTHONCOMMAND) $< $(writerfilter_GEN_ooxml_Model_processed)) > $@ -$(writerfilter_GEN_ooxml_FactoryValues_hxx) : $(writerfilter_SRC_ooxml_FactoryValues_py) $(writerfilter_GEN_ooxml_Model_processed) - $(call gb_Output_announce,$(subst $(WORKDIR)/,,$@),build,PY ,1) - $(call gb_Helper_abbreviate_dirs, $(writerfilter_PYTHONCOMMAND) $(writerfilter_SRC_ooxml_FactoryValues_py) $(writerfilter_GEN_ooxml_Model_processed)) > $@ - $(writerfilter_GEN_ooxml_FastTokens_hxx) : $(writerfilter_SRC_ooxml_FastTokens_py) $(writerfilter_GEN_ooxml_Token_xml) | $(writerfilter_WORK)/ooxml/.dir $(call gb_Output_announce,$(subst $(WORKDIR)/,,$@),build,PY ,1) $(call gb_Helper_abbreviate_dirs, $(writerfilter_PYTHONCOMMAND) $(writerfilter_SRC_ooxml_FastTokens_py) $(writerfilter_GEN_ooxml_Token_xml)) > $@ diff --git a/writerfilter/source/ooxml/OOXMLFactory.cxx b/writerfilter/source/ooxml/OOXMLFactory.cxx index afdadf1..5f8512f 100644 --- a/writerfilter/source/ooxml/OOXMLFactory.cxx +++ b/writerfilter/source/ooxml/OOXMLFactory.cxx @@ -62,14 +62,6 @@ AttributeToResourceMapPointer OOXMLFactory_ns::getAttributeToResourceMap(Id nId) return m_AttributesMap[nId]; } -ListValueMapPointer OOXMLFactory_ns::getListValueMap(Id nId) -{ - if (m_ListValuesMap.find(nId) == m_ListValuesMap.end()) - m_ListValuesMap[nId] = createListValueMap(nId); - - return m_ListValuesMap[nId]; -} - CreateElementMapPointer OOXMLFactory_ns::getCreateElementMap(Id nId) { if (m_CreateElementsMap.find(nId) == m_CreateElementsMap.end()) @@ -191,13 +183,9 @@ void OOXMLFactory::attributes(OOXMLFastContextHandler * pHandler, break; case RT_List: { - ListValueMapPointer pListValueMap = - pFactory->getListValueMap(aIt->second.m_nRef); - - if (pListValueMap.get() != NULL) + sal_uInt32 nValue; + if (pFactory->getListValue(aIt->second.m_nRef, Attribs->getValue(nToken), nValue)) { - OUString aValue(Attribs->getValue(nToken)); - sal_uInt32 nValue = (*pListValueMap)[aValue]; OOXMLValue::Pointer_t xValue = OOXMLIntegerValue::Create(nValue); pHandler->newProperty(nId, xValue); pFactory->attributeAction(pHandler, nToken, xValue); diff --git a/writerfilter/source/ooxml/OOXMLFactory.hxx b/writerfilter/source/ooxml/OOXMLFactory.hxx index 76676ac..6167290 100644 --- a/writerfilter/source/ooxml/OOXMLFactory.hxx +++ b/writerfilter/source/ooxml/OOXMLFactory.hxx @@ -70,10 +70,6 @@ typedef boost::unordered_map<Token_t, AttributeInfo> AttributeToResourceMap; typedef boost::shared_ptr<AttributeToResourceMap> AttributeToResourceMapPointer; typedef boost::unordered_map<Id, AttributeToResourceMapPointer> AttributesMap; -typedef boost::unordered_map<OUString, sal_Int32, OUStringHash> ListValueMap; -typedef boost::shared_ptr<ListValueMap> ListValueMapPointer; -typedef boost::unordered_map<Id, ListValueMapPointer> ListValuesMap; - struct CreateElement { ResourceType_t m_nResource; @@ -106,7 +102,6 @@ public: #endif AttributeToResourceMapPointer getAttributeToResourceMap(Id nId); - ListValueMapPointer getListValueMap(Id nId); CreateElementMapPointer getCreateElementMap(Id nId); TokenToIdMapPointer getTokenToIdMap(Id nId); @@ -114,14 +109,15 @@ protected: virtual ~OOXMLFactory_ns(); AttributesMap m_AttributesMap; - ListValuesMap m_ListValuesMap; CreateElementsMap m_CreateElementsMap; TokenToIdsMap m_TokenToIdsMap; virtual AttributeToResourceMapPointer createAttributeToResourceMap(Id nId) = 0; - virtual ListValueMapPointer createListValueMap(Id nId) = 0; virtual CreateElementMapPointer createCreateElementMap(Id nId) = 0; virtual TokenToIdMapPointer createTokenToIdMap(Id nId) = 0; + +public: + virtual bool getListValue(Id nId, const OUString& rValue, sal_uInt32& rOutValue) = 0; }; class OOXMLFactory diff --git a/writerfilter/source/ooxml/factory_ns.py b/writerfilter/source/ooxml/factory_ns.py index 991d23a..4ccbf3c 100644 --- a/writerfilter/source/ooxml/factory_ns.py +++ b/writerfilter/source/ooxml/factory_ns.py @@ -36,7 +36,7 @@ public: static Pointer_t getInstance(); virtual AttributeToResourceMapPointer createAttributeToResourceMap(Id nId); - virtual ListValueMapPointer createListValueMap(Id nId); + virtual bool getListValue(Id nId, const OUString& rValue, sal_uInt32& rOutValue); virtual CreateElementMapPointer createCreateElementMap(Id nId); virtual TokenToIdMapPointer createTokenToIdMap(Id nId); #ifdef DEBUG_DOMAINMAPPER diff --git a/writerfilter/source/ooxml/factory_values.py b/writerfilter/source/ooxml/factory_values.py deleted file mode 100644 index 1279e9d..0000000 --- a/writerfilter/source/ooxml/factory_values.py +++ /dev/null @@ -1,59 +0,0 @@ -#!/usr/bin/env python -# -# 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/. -# - -from __future__ import print_function -import xml.sax -import string -import sys - - -class ContentHandler(xml.sax.handler.ContentHandler): - def __init__(self): - self.inValue = False - self.defines = [] - self.chars = [] - - def __escape(self, name): - return name.replace('-', 'm').replace('+', 'p').replace(' ', '_').replace(',', '_') - - def startDocument(self): - print(''' -#ifndef INCLUDED_FACTORY_VALUES -#include <rtl/ustring.hxx> - -#define OOXMLValueString_ ""''') - - def endDocument(self): - print(""" -#endif // INCLUDED_FACTORY_VALUES""") - - def startElement(self, name, attrs): - if name == "value": - self.inValue = True - - def endElement(self, name): - if name == "value": - self.inValue = False - characters = "".join(self.chars) - self.chars = [] - if len(characters): - define = '#define OOXMLValueString_%s "%s"' % (self.__escape(characters), characters) - if not define in self.defines: - self.defines.append(define) - print(define) - - def characters(self, chars): - if self.inValue: - self.chars.append(chars) - -parser = xml.sax.make_parser() -parser.setContentHandler(ContentHandler()) -parser.parse(sys.argv[1]) - -# vim:set shiftwidth=4 softtabstop=4 expandtab: diff --git a/writerfilter/source/ooxml/factoryimpl_ns.py b/writerfilter/source/ooxml/factoryimpl_ns.py index 687814d..6fc9550 100644 --- a/writerfilter/source/ooxml/factoryimpl_ns.py +++ b/writerfilter/source/ooxml/factoryimpl_ns.py @@ -178,7 +178,7 @@ def factoryAttributeToResourceMap(nsNode): print() -# factoryListValueMap +# factoryGetListValue def idToLabel(idName): @@ -193,28 +193,33 @@ def valueToLabel(value): return value.replace('-', 'm').replace('+', 'p').replace(' ', '_').replace(',', '_') -def factoryListValueMap(nsNode): - print("""ListValueMapPointer OOXMLFactory_%s::createListValueMap(Id nId) +def factoryGetListValue(nsNode): + print("""bool OOXMLFactory_%s::getListValue(Id nId, const OUString& rValue, sal_uInt32& rOutValue) { - ListValueMapPointer pMap(new ListValueMap()); + (void) rValue; + (void) rOutValue; switch (nId) {""" % nsToLabel(nsNode)) for resourceNode in [i for i in getChildrenByName(nsNode, "resource") if i.getAttribute("resource") == "List"]: print(" case %s:" % idForDefine(nsNode, resourceNode)) + output_else = "" for valueNode in getChildrenByName(resourceNode, "value"): valueData = "" if len(valueNode.childNodes): valueData = valueNode.childNodes[0].data - print(" (*pMap)[OOXMLValueString_%s] = %s;" % (valueToLabel(valueData), idToLabel(valueNode.getAttribute("tokenid")))) + print(" %sif (rValue == \"%s\") { rOutValue = %s; }" % (output_else, valueData, idToLabel(valueNode.getAttribute("tokenid")))) + output_else = "else " + print(" %s{ return false; }" % (output_else)) + print(" return true;") print(" break;") print(""" default: break; } - return pMap; + return false; }""") @@ -343,13 +348,6 @@ def charactersActionForValues(nsNode, refNode): if dataNode.getAttribute("type") == "int": ret.append(" OOXMLValue::Pointer_t pValue(new OOXMLIntegerValue(sText));") ret.append(" pValueHandler->setValue(pValue);") - elif dataNode.getAttribute("type") == "list": - ret.append(" ListValueMapPointer pListValueMap = getListValueMap(nDefine);") - ret.append(" if (pListValueMap.get() != NULL)") - ret.append(" {") - ret.append(" OOXMLValue::Pointer_t pValue(new OOXMLIntegerValue((*pListValueMap)[sText]));") - ret.append(" pValueHandler->setValue(pValue);") - ret.append(" }") ret.append(" }") return ret @@ -646,7 +644,6 @@ def getChildrenByName(parentNode, childName): def createImpl(modelNode, nsName): print(""" #include "ooxml/resourceids.hxx" -#include "OOXMLFactory_values.hxx" #include "OOXMLFactory_%s.hxx" #include "ooxml/OOXMLFastHelper.hxx" @@ -673,7 +670,7 @@ namespace ooxml { factoryDestructor(nsLabel) factoryGetInstance(nsLabel) factoryAttributeToResourceMap(nsNode) - factoryListValueMap(nsNode) + factoryGetListValue(nsNode) factoryCreateElementMap(files, nsNode) factoryActions(nsNode) factoryGetDefineName(nsNode) _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits