diff options
author | Jan Holesovsky <kendy@collabora.com> | 2014-08-07 08:27:45 +0200 |
---|---|---|
committer | Jan Holesovsky <kendy@collabora.com> | 2014-08-07 15:21:46 +0200 |
commit | 345a3a394e082595924bf219796627f6c00ae2dd (patch) | |
tree | 788d498b6fac403305fe911dd7e7ebaac8e9d2b9 | |
parent | 6c4de449094048465b81abf93139bb5950fa12c9 (diff) |
writerfilter: Kill AttributeToResourceMap.
IMPORTANT: From now on, the order of attributes becomes stable, based on the
order in model.xml (not on implementation details of unordered_map), and the
code that handles attributes may depend on a particular order. If you want to
change the order how the attributes are handled, change model.xml, and check
you achieved what you wanted in the generated ::getAttributeInfoArray()'s.
[Writerfilter loses another 250k (stripped dbgutil). And the usage of
unordered_map here was just completely bogus from the very beginning, as it
was only iterated as a normal array anyway ;-)]
Change-Id: Ic70c37793e313c4ccda1d6f374cc2d366307ba1b
-rw-r--r-- | writerfilter/source/ooxml/OOXMLFactory.cxx | 35 | ||||
-rw-r--r-- | writerfilter/source/ooxml/OOXMLFactory.hxx | 14 | ||||
-rw-r--r-- | writerfilter/source/ooxml/factory_ns.py | 2 | ||||
-rw-r--r-- | writerfilter/source/ooxml/factoryimpl_ns.py | 36 |
4 files changed, 34 insertions, 53 deletions
diff --git a/writerfilter/source/ooxml/OOXMLFactory.cxx b/writerfilter/source/ooxml/OOXMLFactory.cxx index 75bee9750914..1318c9e8d12b 100644 --- a/writerfilter/source/ooxml/OOXMLFactory.cxx +++ b/writerfilter/source/ooxml/OOXMLFactory.cxx @@ -30,16 +30,6 @@ namespace ooxml { using namespace com::sun::star; -AttributeInfo::AttributeInfo() -:m_nResource(RT_NoResource), m_nRef(0) -{ -} - -AttributeInfo::AttributeInfo(ResourceType_t nResource, Id nRef) - :m_nResource(nResource), m_nRef(nRef) -{ -} - CreateElement::CreateElement() :m_nResource(RT_NoResource), m_nId(0) { @@ -56,14 +46,6 @@ OOXMLFactory_ns::~OOXMLFactory_ns() { } -AttributeToResourceMapPointer OOXMLFactory_ns::getAttributeToResourceMap(Id nId) -{ - if (m_AttributesMap.find(nId) == m_AttributesMap.end()) - m_AttributesMap[nId] = createAttributeToResourceMap(nId); - - return m_AttributesMap[nId]; -} - CreateElementMapPointer OOXMLFactory_ns::getCreateElementMap(Id nId) { if (m_CreateElementsMap.find(nId) == m_CreateElementsMap.end()) @@ -105,23 +87,22 @@ void OOXMLFactory::attributes(OOXMLFastContextHandler * pHandler, if (pFactory.get() != NULL) { - AttributeToResourceMapPointer pMap = pFactory->getAttributeToResourceMap(nDefine); - - AttributeToResourceMap::const_iterator aIt; - AttributeToResourceMap::const_iterator aEndIt = pMap->end(); - assert( dynamic_cast< sax_fastparser::FastAttributeList *>( Attribs.get() ) != NULL ); sax_fastparser::FastAttributeList *pAttribs; pAttribs = static_cast< sax_fastparser::FastAttributeList *>( Attribs.get() ); - for (aIt = pMap->begin(); aIt != aEndIt; ++aIt) + const AttributeInfo *pAttr = pFactory->getAttributeInfoArray(nDefine); + if (!pAttr) + return; + + for (; pAttr->m_nToken != -1; ++pAttr) { - sal_Int32 nToken = aIt->first; + sal_Int32 nToken = pAttr->m_nToken; if (pAttribs->hasAttribute(nToken)) { Id nId = pFactory->getResourceId(nDefine, nToken); - switch (aIt->second.m_nResource) + switch (pAttr->m_nResource) { case RT_Boolean: { @@ -170,7 +151,7 @@ void OOXMLFactory::attributes(OOXMLFastContextHandler * pHandler, case RT_List: { sal_uInt32 nValue; - if (pFactory->getListValue(aIt->second.m_nRef, Attribs->getValue(nToken), nValue)) + if (pFactory->getListValue(pAttr->m_nRef, Attribs->getValue(nToken), nValue)) { OOXMLValue::Pointer_t xValue = OOXMLIntegerValue::Create(nValue); pHandler->newProperty(nId, xValue); diff --git a/writerfilter/source/ooxml/OOXMLFactory.hxx b/writerfilter/source/ooxml/OOXMLFactory.hxx index f171b701d17a..67a3e95c4bed 100644 --- a/writerfilter/source/ooxml/OOXMLFactory.hxx +++ b/writerfilter/source/ooxml/OOXMLFactory.hxx @@ -59,17 +59,11 @@ enum ResourceType_t { struct AttributeInfo { + Token_t m_nToken; ResourceType_t m_nResource; Id m_nRef; - - AttributeInfo(ResourceType_t nResource, Id nRef); - AttributeInfo(); }; -typedef boost::unordered_map<Token_t, AttributeInfo> AttributeToResourceMap; -typedef boost::shared_ptr<AttributeToResourceMap> AttributeToResourceMapPointer; -typedef boost::unordered_map<Id, AttributeToResourceMapPointer> AttributesMap; - struct CreateElement { ResourceType_t m_nResource; @@ -82,8 +76,6 @@ struct CreateElement typedef boost::unordered_map<Token_t, CreateElement> CreateElementMap; typedef boost::shared_ptr<CreateElementMap> CreateElementMapPointer; typedef boost::unordered_map<Id, CreateElementMapPointer> CreateElementsMap; -typedef boost::unordered_map<Id, std::string> IdToStringMap; -typedef boost::shared_ptr<IdToStringMap> IdToStringMapPointer; class OOXMLFactory_ns { public: @@ -94,21 +86,19 @@ public: virtual void endAction(OOXMLFastContextHandler * pHandler); virtual void attributeAction(OOXMLFastContextHandler * pHandler, Token_t nToken, OOXMLValue::Pointer_t pValue); - AttributeToResourceMapPointer getAttributeToResourceMap(Id nId); CreateElementMapPointer getCreateElementMap(Id nId); protected: virtual ~OOXMLFactory_ns(); - AttributesMap m_AttributesMap; CreateElementsMap m_CreateElementsMap; - virtual AttributeToResourceMapPointer createAttributeToResourceMap(Id nId) = 0; virtual CreateElementMapPointer createCreateElementMap(Id nId) = 0; public: virtual bool getListValue(Id nId, const OUString& rValue, sal_uInt32& rOutValue) = 0; virtual Id getResourceId(Id nDefine, sal_Int32 nToken) = 0; + virtual const AttributeInfo* getAttributeInfoArray(Id nId) = 0; }; class OOXMLFactory diff --git a/writerfilter/source/ooxml/factory_ns.py b/writerfilter/source/ooxml/factory_ns.py index 2ab88890253a..f275ed449cf1 100644 --- a/writerfilter/source/ooxml/factory_ns.py +++ b/writerfilter/source/ooxml/factory_ns.py @@ -35,7 +35,7 @@ public: static Pointer_t getInstance(); - virtual AttributeToResourceMapPointer createAttributeToResourceMap(Id nId); + virtual const AttributeInfo* getAttributeInfoArray(Id nId); virtual CreateElementMapPointer createCreateElementMap(Id nId); virtual bool getListValue(Id nId, const OUString& rValue, sal_uInt32& rOutValue); virtual Id getResourceId(Id nDefine, sal_Int32 nToken); diff --git a/writerfilter/source/ooxml/factoryimpl_ns.py b/writerfilter/source/ooxml/factoryimpl_ns.py index 5263d9f29b20..eee675e4a463 100644 --- a/writerfilter/source/ooxml/factoryimpl_ns.py +++ b/writerfilter/source/ooxml/factoryimpl_ns.py @@ -9,6 +9,7 @@ from __future__ import print_function from xml.dom import minidom +from collections import OrderedDict import sys @@ -125,8 +126,8 @@ def fastToken(attrNode): return "".join(ret) -def factoryAttributeToResourceMapInner(nsNode, defineNode): - ret = [] +def collectAttributeToResource(nsNode, defineNode): + ret = OrderedDict() defineName = defineNode.getAttribute("name") for refNode in getChildrenByName(defineNode, "ref"): refName = refNode.getAttribute("name") @@ -134,13 +135,11 @@ def factoryAttributeToResourceMapInner(nsNode, defineNode): if parent.localName in ("element", "attribute"): continue for define in [i for i in getChildrenByName(getChildByName(nsNode, "grammar"), "define") if i.getAttribute("name") == refName]: - ret.extend(factoryAttributeToResourceMapInner(nsNode, define)) + ret.update(collectAttributeToResource(nsNode, define)) attrNodes = defineNode.getElementsByTagName("attribute") for attrNode in attrNodes: attrToken = fastToken(attrNode) - if attrNode == attrNodes[0]: - ret.append(" // %s" % defineName) resourceName = resourceForAttribute(nsNode, attrNode) refDefine = "0" if len(resourceName): @@ -148,32 +147,42 @@ def factoryAttributeToResourceMapInner(nsNode, defineNode): refName = refNode.getAttribute("name") for define in [i for i in getChildrenByName(getChildByName(nsNode, "grammar"), "define") if i.getAttribute("name") == refName]: refDefine = idForDefine(nsNode, define) - ret.append(" (*pMap)[%s] = AttributeInfo(RT_%s, %s);" % (attrToken, resourceName, refDefine)) - else: - ret.append(" // empty resource: %s" % fastToken(attrNode)) + ret[attrToken] = "RT_%s, %s" % (resourceName, refDefine) + + return ret + +def factoryAttributeToResourceMapInner(nsNode, defineNode): + ret = [] + attributes = collectAttributeToResource(nsNode, defineNode) + for k in attributes.keys(): + ret.append(" { %s, %s }," % (k, attributes[k])) return ret def factoryAttributeToResourceMap(nsNode): - print("""AttributeToResourceMapPointer OOXMLFactory_%s::createAttributeToResourceMap(Id nId) + print("""const AttributeInfo* OOXMLFactory_%s::getAttributeInfoArray(Id nId) { - AttributeToResourceMapPointer pMap(new AttributeToResourceMap()); - switch (nId) {""" % nsToLabel(nsNode)) for defineNode in getChildrenByName(getChildByName(nsNode, "grammar"), "define"): inner = "\n".join(factoryAttributeToResourceMapInner(nsNode, defineNode)) if len(inner): print(" case %s:" % idForDefine(nsNode, defineNode)) + print(" {") + print(" const static AttributeInfo info[] = {") print(inner) + print(" { -1, RT_NoResource, 0 }") + print(" };") + print(" return info;") + print(" }") print(" break;") print(""" default: break; } - return pMap; + return NULL; }""") print() @@ -250,7 +259,8 @@ def factoryGetListValue(nsNode): } return false; -}""") +} +""") # factoryCreateElementMap |