[Libreoffice-commits] core.git: 2 commits - writerfilter/source
Jan Holesovsky
kendy at collabora.com
Wed Aug 6 02:48:52 PDT 2014
writerfilter/source/ooxml/OOXMLFactory.cxx | 18 ------
writerfilter/source/ooxml/OOXMLFactory.hxx | 11 ----
writerfilter/source/ooxml/factory_ns.py | 7 --
writerfilter/source/ooxml/factoryimpl.py | 3 -
writerfilter/source/ooxml/factoryimpl_ns.py | 76 ++++++++++------------------
5 files changed, 34 insertions(+), 81 deletions(-)
New commits:
commit 8ec7e5250c204422b5efdf277de0722adb042728
Author: Jan Holesovsky <kendy at collabora.com>
Date: Wed Aug 6 11:36:30 2014 +0200
writerfilter: getDefineName() is unused, kill it.
Change-Id: I7d733a509f8256d0c2bfbb4bbd91ed6924452051
diff --git a/writerfilter/source/ooxml/OOXMLFactory.cxx b/writerfilter/source/ooxml/OOXMLFactory.cxx
index d066d25..75bee97 100644
--- a/writerfilter/source/ooxml/OOXMLFactory.cxx
+++ b/writerfilter/source/ooxml/OOXMLFactory.cxx
@@ -72,13 +72,6 @@ CreateElementMapPointer OOXMLFactory_ns::getCreateElementMap(Id nId)
return m_CreateElementsMap[nId];
}
-#ifdef DEBUG_DOMAINMAPPER
-std::string OOXMLFactory_ns::getDefineName(Id /*nId*/) const
-{
- return "";
-}
-#endif
-
// class OOXMLFactory
typedef rtl::Static< osl::Mutex, OOXMLFactory > OOXMLFactory_Mutex;
diff --git a/writerfilter/source/ooxml/OOXMLFactory.hxx b/writerfilter/source/ooxml/OOXMLFactory.hxx
index c72c52b..f171b70 100644
--- a/writerfilter/source/ooxml/OOXMLFactory.hxx
+++ b/writerfilter/source/ooxml/OOXMLFactory.hxx
@@ -93,9 +93,6 @@ public:
virtual void charactersAction(OOXMLFastContextHandler * pHandler, const OUString & rString);
virtual void endAction(OOXMLFastContextHandler * pHandler);
virtual void attributeAction(OOXMLFastContextHandler * pHandler, Token_t nToken, OOXMLValue::Pointer_t pValue);
-#ifdef DEBUG_DOMAINMAPPER
- virtual std::string getDefineName(Id nId) const;
-#endif
AttributeToResourceMapPointer getAttributeToResourceMap(Id nId);
CreateElementMapPointer getCreateElementMap(Id nId);
diff --git a/writerfilter/source/ooxml/factory_ns.py b/writerfilter/source/ooxml/factory_ns.py
index e13c6af..2ab8889 100644
--- a/writerfilter/source/ooxml/factory_ns.py
+++ b/writerfilter/source/ooxml/factory_ns.py
@@ -39,9 +39,6 @@ public:
virtual CreateElementMapPointer createCreateElementMap(Id nId);
virtual bool getListValue(Id nId, const OUString& rValue, sal_uInt32& rOutValue);
virtual Id getResourceId(Id nDefine, sal_Int32 nToken);
-#ifdef DEBUG_DOMAINMAPPER
- virtual string getDefineName(Id nId) const;
-#endif
""" % nsToken)
actions = []
diff --git a/writerfilter/source/ooxml/factoryimpl_ns.py b/writerfilter/source/ooxml/factoryimpl_ns.py
index 7b6eeac..73282d8 100644
--- a/writerfilter/source/ooxml/factoryimpl_ns.py
+++ b/writerfilter/source/ooxml/factoryimpl_ns.py
@@ -507,31 +507,6 @@ def factoryActions(nsNode):
print()
-# factoryGetDefineName
-
-
-def factoryGetDefineName(nsNode):
- print("""#ifdef DEBUG_DOMAINMAPPER
-string OOXMLFactory_%s::getDefineName(Id nId) const
-{
- static IdToStringMapPointer pMap;
-
- if (pMap.get() == NULL)
- {
- pMap = IdToStringMapPointer(new IdToStringMap());
-
-""" % nsToLabel(nsNode))
- for defineNode in getChildrenByName(getChildByName(nsNode, "grammar"), "define"):
- print(""" (*pMap)[%s] = "%s";""" % (idForDefine(nsNode, defineNode), defineNode.getAttribute("name")))
- print(""" }
-
- return (*pMap)[nId];
-}
-#endif
-
-""")
-
-
# factoryGetResourceId
@@ -704,7 +679,6 @@ namespace ooxml {
factoryGetListValue(nsNode)
factoryCreateElementMap(files, nsNode)
factoryActions(nsNode)
- factoryGetDefineName(nsNode)
factoryGetResourceId(nsNode)
factoryAttributeAction(nsNode)
commit 9ff65cb532fb066c7f3ffc4176290eefc3ac8cdf
Author: Jan Holesovsky <kendy at collabora.com>
Date: Wed Aug 6 11:25:51 2014 +0200
writerfilter: Kill TokenToIdsMap's, and use switches instead.
This seems to save another nearly 300k; and I guess the compiler will optimize
it better than using the unordered_map.
Change-Id: I5df5cd2afe3f4bedad69e1e3477211842c40a90c
diff --git a/writerfilter/source/ooxml/OOXMLFactory.cxx b/writerfilter/source/ooxml/OOXMLFactory.cxx
index de24d2c..d066d25 100644
--- a/writerfilter/source/ooxml/OOXMLFactory.cxx
+++ b/writerfilter/source/ooxml/OOXMLFactory.cxx
@@ -72,14 +72,6 @@ CreateElementMapPointer OOXMLFactory_ns::getCreateElementMap(Id nId)
return m_CreateElementsMap[nId];
}
-TokenToIdMapPointer OOXMLFactory_ns::getTokenToIdMap(Id nId)
-{
- if (m_TokenToIdsMap.find(nId) == m_TokenToIdsMap.end())
- m_TokenToIdsMap[nId] = createTokenToIdMap(nId);
-
- return m_TokenToIdsMap[nId];
-}
-
#ifdef DEBUG_DOMAINMAPPER
std::string OOXMLFactory_ns::getDefineName(Id /*nId*/) const
{
@@ -120,7 +112,6 @@ void OOXMLFactory::attributes(OOXMLFastContextHandler * pHandler,
if (pFactory.get() != NULL)
{
- TokenToIdMapPointer pTokenToIdMap = pFactory->getTokenToIdMap(nDefine);
AttributeToResourceMapPointer pMap = pFactory->getAttributeToResourceMap(nDefine);
AttributeToResourceMap::const_iterator aIt;
@@ -135,7 +126,7 @@ void OOXMLFactory::attributes(OOXMLFastContextHandler * pHandler,
sal_Int32 nToken = aIt->first;
if (pAttribs->hasAttribute(nToken))
{
- Id nId = (*pTokenToIdMap)[nToken];
+ Id nId = pFactory->getResourceId(nDefine, nToken);
switch (aIt->second.m_nResource)
{
diff --git a/writerfilter/source/ooxml/OOXMLFactory.hxx b/writerfilter/source/ooxml/OOXMLFactory.hxx
index bfa93c7..c72c52b 100644
--- a/writerfilter/source/ooxml/OOXMLFactory.hxx
+++ b/writerfilter/source/ooxml/OOXMLFactory.hxx
@@ -85,10 +85,6 @@ typedef boost::unordered_map<Id, CreateElementMapPointer> CreateElementsMap;
typedef boost::unordered_map<Id, std::string> IdToStringMap;
typedef boost::shared_ptr<IdToStringMap> IdToStringMapPointer;
-typedef boost::unordered_map<Id, Token_t> TokenToIdMap;
-typedef boost::shared_ptr<TokenToIdMap> TokenToIdMapPointer;
-typedef boost::unordered_map<Id, TokenToIdMapPointer> TokenToIdsMap;
-
class OOXMLFactory_ns {
public:
typedef boost::shared_ptr<OOXMLFactory_ns> Pointer_t;
@@ -103,21 +99,19 @@ public:
AttributeToResourceMapPointer getAttributeToResourceMap(Id nId);
CreateElementMapPointer getCreateElementMap(Id nId);
- TokenToIdMapPointer getTokenToIdMap(Id nId);
protected:
virtual ~OOXMLFactory_ns();
AttributesMap m_AttributesMap;
CreateElementsMap m_CreateElementsMap;
- TokenToIdsMap m_TokenToIdsMap;
virtual AttributeToResourceMapPointer createAttributeToResourceMap(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;
+ virtual Id getResourceId(Id nDefine, sal_Int32 nToken) = 0;
};
class OOXMLFactory
diff --git a/writerfilter/source/ooxml/factory_ns.py b/writerfilter/source/ooxml/factory_ns.py
index 4ccbf3c..e13c6af 100644
--- a/writerfilter/source/ooxml/factory_ns.py
+++ b/writerfilter/source/ooxml/factory_ns.py
@@ -36,9 +36,9 @@ public:
static Pointer_t getInstance();
virtual AttributeToResourceMapPointer createAttributeToResourceMap(Id nId);
- virtual bool getListValue(Id nId, const OUString& rValue, sal_uInt32& rOutValue);
virtual CreateElementMapPointer createCreateElementMap(Id nId);
- virtual TokenToIdMapPointer createTokenToIdMap(Id nId);
+ virtual bool getListValue(Id nId, const OUString& rValue, sal_uInt32& rOutValue);
+ virtual Id getResourceId(Id nDefine, sal_Int32 nToken);
#ifdef DEBUG_DOMAINMAPPER
virtual string getDefineName(Id nId) const;
#endif
diff --git a/writerfilter/source/ooxml/factoryimpl.py b/writerfilter/source/ooxml/factoryimpl.py
index 1f6e251..05284ee 100644
--- a/writerfilter/source/ooxml/factoryimpl.py
+++ b/writerfilter/source/ooxml/factoryimpl.py
@@ -30,11 +30,10 @@ def createFastChildContextFromFactory(model):
if (pFactory.get() != NULL)
{
CreateElementMapPointer pMap = pFactory->getCreateElementMap(nDefine);
- TokenToIdMapPointer pTokenMap = pFactory->getTokenToIdMap(nDefine);
if (pMap.get() != NULL)
{
- Id nId = (*pTokenMap)[Element];
+ Id nId = pFactory->getResourceId(nDefine, Element);
CreateElement aCreateElement = (*pMap)[Element];
switch (aCreateElement.m_nResource)
diff --git a/writerfilter/source/ooxml/factoryimpl_ns.py b/writerfilter/source/ooxml/factoryimpl_ns.py
index d6457ee..7b6eeac 100644
--- a/writerfilter/source/ooxml/factoryimpl_ns.py
+++ b/writerfilter/source/ooxml/factoryimpl_ns.py
@@ -532,64 +532,72 @@ string OOXMLFactory_%s::getDefineName(Id nId) const
""")
-# factoryTokenToIdMap
+# factoryGetResourceId
-def factoryTokenToIdMapInner(nsNode, defineNode):
- ret = []
+def collectTokenToId(nsNode, defineNode):
+ ret = {}
for refNode in defineNode.getElementsByTagName("ref"):
refName = refNode.getAttribute("name")
parent = refNode.parentNode
if parent.localName in ("element", "attribute"):
continue
- refblock1 = []
+ refblock1 = {}
for define in [i for i in getChildrenByName(getChildByName(nsNode, "grammar"), "define") if i.getAttribute("name") == refName]:
- refblock1.extend(factoryTokenToIdMapInner(nsNode, define))
+ refblock1.update(collectTokenToId(nsNode, define))
if not len(refblock1):
for namespaceNode in getChildrenByName(nsNode.parentNode, "namespace"):
for define in [i for i in getChildrenByName(getChildByName(namespaceNode, "grammar"), "define") if i.getAttribute("name") == refName]:
- ret.extend(factoryTokenToIdMapInner(namespaceNode, define))
+ ret.update(collectTokenToId(namespaceNode, define))
else:
- ret.extend(refblock1)
+ ret.update(refblock1)
- body = []
defineName = defineNode.getAttribute("name")
for resourceNode in [i for i in getChildrenByName(nsNode, "resource") if i.getAttribute("name") == defineName]:
for node in [i for i in resourceNode.childNodes if i.localName in ("element", "attribute")]:
if node.hasAttribute("tokenid"):
- body.append("(*pMap)[%s] = %s;" % (fastToken(node), idToLabel(node.getAttribute("tokenid"))))
- if len(body):
- ret.append("// %s" % defineName)
- ret.extend(body)
+ ret[fastToken(node)] = idToLabel(node.getAttribute("tokenid"))
return ret
+def factoryTokenToIdMapInner(nsNode, defineNode):
+ ids = collectTokenToId(nsNode, defineNode)
+ ret = []
+ for i in ids.keys():
+ ret.append(" case %s: return %s;" % (i, ids[i]))
+
+ return ret
-def factoryTokenToIdMap(nsNode):
- print("""TokenToIdMapPointer OOXMLFactory_%s::createTokenToIdMap(Id nId)
+def factoryGetResourceId(nsNode):
+ print("""Id OOXMLFactory_%s::getResourceId(Id nDefine, sal_Int32 nToken)
{
- TokenToIdMapPointer pMap(new TokenToIdMap());
+ (void) nDefine;
+ (void) nToken;
- switch (nId)
+ switch (nDefine)
{""" % nsToLabel(nsNode))
for defineNode in getChildrenByName(getChildByName(nsNode, "grammar"), "define"):
inner = "\n".join(factoryTokenToIdMapInner(nsNode, defineNode))
if len(inner):
print(" case %s:" % idForDefine(nsNode, defineNode))
+ print(" switch (nToken)")
+ print(" {")
print(inner)
+ print(" }")
print(" break;")
print(" default:")
+ print(" switch (nToken)")
+ print(" {")
for startNode in getChildrenByName(nsNode, "start"):
startName = startNode.getAttribute("name")
- print(" // %s" % startName)
for defineNode in [i for i in getChildrenByName(getChildByName(nsNode, "grammar"), "define") if i.getAttribute("name") == startName]:
inner = factoryTokenToIdMapInner(nsNode, defineNode)
if len(inner):
print("\n".join(inner))
- print(""" break;
+ print(""" }
+ break;
}
-
- return pMap;
+ return 0;
}
""")
@@ -697,7 +705,7 @@ namespace ooxml {
factoryCreateElementMap(files, nsNode)
factoryActions(nsNode)
factoryGetDefineName(nsNode)
- factoryTokenToIdMap(nsNode)
+ factoryGetResourceId(nsNode)
factoryAttributeAction(nsNode)
print("""/// @endcond
More information about the Libreoffice-commits
mailing list