Kaydet (Commit) 1ae698ad authored tarafından Jan Holesovsky's avatar Jan Holesovsky

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
üst 7d711899
......@@ -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)) > $@
......
......@@ -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);
......
......@@ -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
......
......@@ -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
......
#!/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:
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment