Kaydet (Commit) 345a3a39 authored tarafından Jan Holesovsky's avatar Jan Holesovsky

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
üst 6c4de449
...@@ -30,16 +30,6 @@ namespace ooxml { ...@@ -30,16 +30,6 @@ namespace ooxml {
using namespace com::sun::star; 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() CreateElement::CreateElement()
:m_nResource(RT_NoResource), m_nId(0) :m_nResource(RT_NoResource), m_nId(0)
{ {
...@@ -56,14 +46,6 @@ OOXMLFactory_ns::~OOXMLFactory_ns() ...@@ -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) CreateElementMapPointer OOXMLFactory_ns::getCreateElementMap(Id nId)
{ {
if (m_CreateElementsMap.find(nId) == m_CreateElementsMap.end()) if (m_CreateElementsMap.find(nId) == m_CreateElementsMap.end())
...@@ -105,23 +87,22 @@ void OOXMLFactory::attributes(OOXMLFastContextHandler * pHandler, ...@@ -105,23 +87,22 @@ void OOXMLFactory::attributes(OOXMLFastContextHandler * pHandler,
if (pFactory.get() != NULL) 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 ); assert( dynamic_cast< sax_fastparser::FastAttributeList *>( Attribs.get() ) != NULL );
sax_fastparser::FastAttributeList *pAttribs; sax_fastparser::FastAttributeList *pAttribs;
pAttribs = static_cast< sax_fastparser::FastAttributeList *>( Attribs.get() ); 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)) if (pAttribs->hasAttribute(nToken))
{ {
Id nId = pFactory->getResourceId(nDefine, nToken); Id nId = pFactory->getResourceId(nDefine, nToken);
switch (aIt->second.m_nResource) switch (pAttr->m_nResource)
{ {
case RT_Boolean: case RT_Boolean:
{ {
...@@ -170,7 +151,7 @@ void OOXMLFactory::attributes(OOXMLFastContextHandler * pHandler, ...@@ -170,7 +151,7 @@ void OOXMLFactory::attributes(OOXMLFastContextHandler * pHandler,
case RT_List: case RT_List:
{ {
sal_uInt32 nValue; 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); OOXMLValue::Pointer_t xValue = OOXMLIntegerValue::Create(nValue);
pHandler->newProperty(nId, xValue); pHandler->newProperty(nId, xValue);
......
...@@ -59,17 +59,11 @@ enum ResourceType_t { ...@@ -59,17 +59,11 @@ enum ResourceType_t {
struct AttributeInfo struct AttributeInfo
{ {
Token_t m_nToken;
ResourceType_t m_nResource; ResourceType_t m_nResource;
Id m_nRef; 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 struct CreateElement
{ {
ResourceType_t m_nResource; ResourceType_t m_nResource;
...@@ -82,8 +76,6 @@ struct CreateElement ...@@ -82,8 +76,6 @@ struct CreateElement
typedef boost::unordered_map<Token_t, CreateElement> CreateElementMap; typedef boost::unordered_map<Token_t, CreateElement> CreateElementMap;
typedef boost::shared_ptr<CreateElementMap> CreateElementMapPointer; typedef boost::shared_ptr<CreateElementMap> CreateElementMapPointer;
typedef boost::unordered_map<Id, CreateElementMapPointer> CreateElementsMap; typedef boost::unordered_map<Id, CreateElementMapPointer> CreateElementsMap;
typedef boost::unordered_map<Id, std::string> IdToStringMap;
typedef boost::shared_ptr<IdToStringMap> IdToStringMapPointer;
class OOXMLFactory_ns { class OOXMLFactory_ns {
public: public:
...@@ -94,21 +86,19 @@ public: ...@@ -94,21 +86,19 @@ public:
virtual void endAction(OOXMLFastContextHandler * pHandler); virtual void endAction(OOXMLFastContextHandler * pHandler);
virtual void attributeAction(OOXMLFastContextHandler * pHandler, Token_t nToken, OOXMLValue::Pointer_t pValue); virtual void attributeAction(OOXMLFastContextHandler * pHandler, Token_t nToken, OOXMLValue::Pointer_t pValue);
AttributeToResourceMapPointer getAttributeToResourceMap(Id nId);
CreateElementMapPointer getCreateElementMap(Id nId); CreateElementMapPointer getCreateElementMap(Id nId);
protected: protected:
virtual ~OOXMLFactory_ns(); virtual ~OOXMLFactory_ns();
AttributesMap m_AttributesMap;
CreateElementsMap m_CreateElementsMap; CreateElementsMap m_CreateElementsMap;
virtual AttributeToResourceMapPointer createAttributeToResourceMap(Id nId) = 0;
virtual CreateElementMapPointer createCreateElementMap(Id nId) = 0; virtual CreateElementMapPointer createCreateElementMap(Id nId) = 0;
public: public:
virtual bool getListValue(Id nId, const OUString& rValue, sal_uInt32& rOutValue) = 0; virtual bool getListValue(Id nId, const OUString& rValue, sal_uInt32& rOutValue) = 0;
virtual Id getResourceId(Id nDefine, sal_Int32 nToken) = 0; virtual Id getResourceId(Id nDefine, sal_Int32 nToken) = 0;
virtual const AttributeInfo* getAttributeInfoArray(Id nId) = 0;
}; };
class OOXMLFactory class OOXMLFactory
......
...@@ -35,7 +35,7 @@ public: ...@@ -35,7 +35,7 @@ public:
static Pointer_t getInstance(); static Pointer_t getInstance();
virtual AttributeToResourceMapPointer createAttributeToResourceMap(Id nId); virtual const AttributeInfo* getAttributeInfoArray(Id nId);
virtual CreateElementMapPointer createCreateElementMap(Id nId); virtual CreateElementMapPointer createCreateElementMap(Id nId);
virtual bool getListValue(Id nId, const OUString& rValue, sal_uInt32& rOutValue); virtual bool getListValue(Id nId, const OUString& rValue, sal_uInt32& rOutValue);
virtual Id getResourceId(Id nDefine, sal_Int32 nToken); virtual Id getResourceId(Id nDefine, sal_Int32 nToken);
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
from __future__ import print_function from __future__ import print_function
from xml.dom import minidom from xml.dom import minidom
from collections import OrderedDict
import sys import sys
...@@ -125,8 +126,8 @@ def fastToken(attrNode): ...@@ -125,8 +126,8 @@ def fastToken(attrNode):
return "".join(ret) return "".join(ret)
def factoryAttributeToResourceMapInner(nsNode, defineNode): def collectAttributeToResource(nsNode, defineNode):
ret = [] ret = OrderedDict()
defineName = defineNode.getAttribute("name") defineName = defineNode.getAttribute("name")
for refNode in getChildrenByName(defineNode, "ref"): for refNode in getChildrenByName(defineNode, "ref"):
refName = refNode.getAttribute("name") refName = refNode.getAttribute("name")
...@@ -134,13 +135,11 @@ def factoryAttributeToResourceMapInner(nsNode, defineNode): ...@@ -134,13 +135,11 @@ def factoryAttributeToResourceMapInner(nsNode, defineNode):
if parent.localName in ("element", "attribute"): if parent.localName in ("element", "attribute"):
continue continue
for define in [i for i in getChildrenByName(getChildByName(nsNode, "grammar"), "define") if i.getAttribute("name") == refName]: 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") attrNodes = defineNode.getElementsByTagName("attribute")
for attrNode in attrNodes: for attrNode in attrNodes:
attrToken = fastToken(attrNode) attrToken = fastToken(attrNode)
if attrNode == attrNodes[0]:
ret.append(" // %s" % defineName)
resourceName = resourceForAttribute(nsNode, attrNode) resourceName = resourceForAttribute(nsNode, attrNode)
refDefine = "0" refDefine = "0"
if len(resourceName): if len(resourceName):
...@@ -148,32 +147,42 @@ def factoryAttributeToResourceMapInner(nsNode, defineNode): ...@@ -148,32 +147,42 @@ def factoryAttributeToResourceMapInner(nsNode, defineNode):
refName = refNode.getAttribute("name") refName = refNode.getAttribute("name")
for define in [i for i in getChildrenByName(getChildByName(nsNode, "grammar"), "define") if i.getAttribute("name") == refName]: for define in [i for i in getChildrenByName(getChildByName(nsNode, "grammar"), "define") if i.getAttribute("name") == refName]:
refDefine = idForDefine(nsNode, define) refDefine = idForDefine(nsNode, define)
ret.append(" (*pMap)[%s] = AttributeInfo(RT_%s, %s);" % (attrToken, resourceName, refDefine)) ret[attrToken] = "RT_%s, %s" % (resourceName, refDefine)
else:
ret.append(" // empty resource: %s" % fastToken(attrNode)) 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 return ret
def factoryAttributeToResourceMap(nsNode): def factoryAttributeToResourceMap(nsNode):
print("""AttributeToResourceMapPointer OOXMLFactory_%s::createAttributeToResourceMap(Id nId) print("""const AttributeInfo* OOXMLFactory_%s::getAttributeInfoArray(Id nId)
{ {
AttributeToResourceMapPointer pMap(new AttributeToResourceMap());
switch (nId) switch (nId)
{""" % nsToLabel(nsNode)) {""" % nsToLabel(nsNode))
for defineNode in getChildrenByName(getChildByName(nsNode, "grammar"), "define"): for defineNode in getChildrenByName(getChildByName(nsNode, "grammar"), "define"):
inner = "\n".join(factoryAttributeToResourceMapInner(nsNode, defineNode)) inner = "\n".join(factoryAttributeToResourceMapInner(nsNode, defineNode))
if len(inner): if len(inner):
print(" case %s:" % idForDefine(nsNode, defineNode)) print(" case %s:" % idForDefine(nsNode, defineNode))
print(" {")
print(" const static AttributeInfo info[] = {")
print(inner) print(inner)
print(" { -1, RT_NoResource, 0 }")
print(" };")
print(" return info;")
print(" }")
print(" break;") print(" break;")
print(""" default: print(""" default:
break; break;
} }
return pMap; return NULL;
}""") }""")
print() print()
...@@ -250,7 +259,8 @@ def factoryGetListValue(nsNode): ...@@ -250,7 +259,8 @@ def factoryGetListValue(nsNode):
} }
return false; return false;
}""") }
""")
# factoryCreateElementMap # factoryCreateElementMap
......
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