solenv/clang-format/blacklist                   |    1 
 writerfilter/Library_writerfilter.mk            |    1 
 writerfilter/inc/ooxml/QNameToString.hxx        |   25 +---------
 writerfilter/source/dmapper/LoggedResources.cxx |    8 +--
 writerfilter/source/ooxml/OOXMLPropertySet.cxx  |    2 
 writerfilter/source/ooxml/qnametostr.py         |   21 ++++++---
 writerfilter/source/ooxml/qnametostrcore.cxx    |   55 ------------------------
 writerfilter/source/rtftok/rtfsprm.cxx          |    2 
 8 files changed, 25 insertions(+), 90 deletions(-)

New commits:
commit 18e5d441ca3c3f0b59db8beaa87e3565489db6f1
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Wed Apr 8 11:49:28 2020 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Wed Apr 8 13:03:58 2020 +0200

    simplify QNameToString
    
    no need for it to be a class, and no need for the data to be allocated
    at runtime
    
    Change-Id: I80bca34b2af221534eae5a6e90de369fa29037e4
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/91878
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/solenv/clang-format/blacklist b/solenv/clang-format/blacklist
index 01f1129e7ee0..95d4390ce95d 100644
--- a/solenv/clang-format/blacklist
+++ b/solenv/clang-format/blacklist
@@ -17804,7 +17804,6 @@ writerfilter/source/ooxml/OOXMLPropertySet.cxx
 writerfilter/source/ooxml/OOXMLPropertySet.hxx
 writerfilter/source/ooxml/OOXMLStreamImpl.cxx
 writerfilter/source/ooxml/OOXMLStreamImpl.hxx
-writerfilter/source/ooxml/qnametostrcore.cxx
 xmlhelp/source/cxxhelp/inc/tvfactory.hxx
 xmlhelp/source/cxxhelp/inc/tvread.hxx
 xmlhelp/source/cxxhelp/provider/content.cxx
diff --git a/writerfilter/Library_writerfilter.mk 
b/writerfilter/Library_writerfilter.mk
index c18e95f1b248..61e62d66e10d 100644
--- a/writerfilter/Library_writerfilter.mk
+++ b/writerfilter/Library_writerfilter.mk
@@ -123,7 +123,6 @@ $(eval $(call 
gb_Library_add_exception_objects,writerfilter,\
     writerfilter/source/ooxml/OOXMLParserState \
     writerfilter/source/ooxml/OOXMLPropertySet \
     writerfilter/source/ooxml/OOXMLStreamImpl \
-    writerfilter/source/ooxml/qnametostrcore \
 ))
 
 $(eval $(call gb_Library_add_generated_exception_objects,writerfilter,\
diff --git a/writerfilter/inc/ooxml/QNameToString.hxx 
b/writerfilter/inc/ooxml/QNameToString.hxx
index 2f3376edbd93..9cdf13de143b 100644
--- a/writerfilter/inc/ooxml/QNameToString.hxx
+++ b/writerfilter/inc/ooxml/QNameToString.hxx
@@ -19,34 +19,15 @@
 #ifndef INCLUDED_WRITERFILTER_INC_OOXML_QNAMETOSTRING_HXX
 #define INCLUDED_WRITERFILTER_INC_OOXML_QNAMETOSTRING_HXX
 
-#include <map>
 #include <string>
 #include <dmapper/resourcemodel.hxx>
 
 namespace writerfilter
 {
 
-class QNameToString final : public virtual SvRefBase
-{
-    typedef tools::SvRef<QNameToString> Pointer_t;
-    typedef std::map < Id, std::string > Map;
-
-    static Pointer_t pInstance;
-
-    void init();
-
-    Map mMap;
-
-    /**
-       Generated.
-     */
-    QNameToString();
-
-public:
-    static Pointer_t const & Instance();
-
-    std::string operator()(Id qName);
-};
+#ifdef DBG_UTIL
+    std::string QNameToString(Id);
+#endif
 
 }
 
diff --git a/writerfilter/source/dmapper/LoggedResources.cxx 
b/writerfilter/source/dmapper/LoggedResources.cxx
index 9fedb159efa8..d8857911ea1d 100644
--- a/writerfilter/source/dmapper/LoggedResources.cxx
+++ b/writerfilter/source/dmapper/LoggedResources.cxx
@@ -258,7 +258,7 @@ void LoggedStream::table(Id name, 
writerfilter::Reference<Table>::Pointer_t ref)
 {
 #ifdef DBG_UTIL
     mHelper.startElement("table");
-    LoggedResourcesHelper::attribute("name", 
(*QNameToString::Instance())(name));
+    LoggedResourcesHelper::attribute("name", QNameToString(name));
 #endif
 
     lcl_table(name, ref);
@@ -272,7 +272,7 @@ void LoggedStream::substream(Id name, 
writerfilter::Reference<Stream>::Pointer_t
 {
 #ifdef DBG_UTIL
     mHelper.startElement("substream");
-    LoggedResourcesHelper::attribute("name", 
(*QNameToString::Instance())(name));
+    LoggedResourcesHelper::attribute("name", QNameToString(name));
 #endif
 
     lcl_substream(name, ref);
@@ -341,7 +341,7 @@ void LoggedProperties::attribute(Id name, Value & val)
 {
 #ifdef DBG_UTIL
     mHelper.startElement("attribute");
-    LoggedResourcesHelper::attribute("name", 
(*QNameToString::Instance())(name));
+    LoggedResourcesHelper::attribute("name", QNameToString(name));
     LoggedResourcesHelper::attribute("value", val.toString());
     LoggedResourcesHelper::endElement();
 #endif
@@ -353,7 +353,7 @@ void LoggedProperties::sprm(Sprm & rSprm)
 {
 #ifdef DBG_UTIL
     mHelper.startElement("sprm");
-    LoggedResourcesHelper::attribute("name", 
(*QNameToString::Instance())(rSprm.getId()));
+    LoggedResourcesHelper::attribute("name", QNameToString(rSprm.getId()));
     LoggedResourcesHelper::chars(rSprm.toString());
 #endif
 
diff --git a/writerfilter/source/ooxml/OOXMLPropertySet.cxx 
b/writerfilter/source/ooxml/OOXMLPropertySet.cxx
index 23a6e7861231..b8071011422b 100644
--- a/writerfilter/source/ooxml/OOXMLPropertySet.cxx
+++ b/writerfilter/source/ooxml/OOXMLPropertySet.cxx
@@ -70,7 +70,7 @@ writerfilter::Reference<Properties>::Pointer_t 
OOXMLProperty::getProps()
 #ifdef DBG_UTIL
 string OOXMLProperty::getName() const
 {
-    string sResult((*QNameToString::Instance())(mId));
+    string sResult(QNameToString(mId));
 
     if (sResult.length() == 0)
         sResult = fastTokenToId(mId);
diff --git a/writerfilter/source/ooxml/qnametostr.py 
b/writerfilter/source/ooxml/qnametostr.py
index 473efc096196..c7fdcc1180da 100644
--- a/writerfilter/source/ooxml/qnametostr.py
+++ b/writerfilter/source/ooxml/qnametostr.py
@@ -20,20 +20,31 @@ class ContentHandler(xml.sax.handler.ContentHandler):
         print("""
 #include "ooxml/resourceids.hxx"
 #include "ooxml/QNameToString.hxx"
+#include "unordered_map"
 
 namespace writerfilter
 {
 
-void QNameToString::init()
-{
 #ifdef DBG_UTIL
+
     /* ooxml */
+    static const std::unordered_map<Id, const char*> g_QNameToStringMap {
 """)
 
     def endDocument(self):
-        print("""#endif
-}
+        print("""
+   };
+
+    std::string QNameToString(Id qName)
+    {
+        auto it = g_QNameToStringMap.find(qName);
+        if (it == g_QNameToStringMap.end())
+            return std::string();
+
+        return it->second;
+    }
 
+#endif
 }
 """)
 
@@ -43,7 +54,7 @@ void QNameToString::init()
                 if v.startswith("ooxml:"):
                     token = v.replace('ooxml:', '')
                     if token not in self.tokens:
-                        print("""    mMap[NS_ooxml::LN_%s] = "ooxml:%s";""" % 
(token, token))
+                        print("""    { NS_ooxml::LN_%s, "ooxml:%s" },""" % 
(token, token))
                         self.tokens.append(token)
 
 
diff --git a/writerfilter/source/ooxml/qnametostrcore.cxx 
b/writerfilter/source/ooxml/qnametostrcore.cxx
deleted file mode 100644
index 0794f5ca427e..000000000000
--- a/writerfilter/source/ooxml/qnametostrcore.cxx
+++ /dev/null
@@ -1,55 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * 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/.
- *
- * This file incorporates work covered by the following license notice:
- *
- *   Licensed to the Apache Software Foundation (ASF) under one or more
- *   contributor license agreements. See the NOTICE file distributed
- *   with this work for additional information regarding copyright
- *   ownership. The ASF licenses this file to you under the Apache
- *   License, Version 2.0 (the "License"); you may not use this file
- *   except in compliance with the License. You may obtain a copy of
- *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-
-#include <ooxml/QNameToString.hxx>
-
-namespace writerfilter
-{
-
-QNameToString::Pointer_t QNameToString::pInstance;
-
-QNameToString::Pointer_t const & QNameToString::Instance()
-{
-    if (pInstance.get() == nullptr)
-        pInstance = QNameToString::Pointer_t(new QNameToString());
-
-    return pInstance;
-}
-
-std::string QNameToString::operator()(Id qName)
-{
-#ifdef DBG_UTIL
-    Map::const_iterator aIt = mMap.find(qName);
-
-    if (aIt != mMap.end())
-        return aIt->second;
-#else
-    (void) qName;
-#endif
-    return std::string();
-}
-
-QNameToString::QNameToString()
-{
-    init();
-}
-
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerfilter/source/rtftok/rtfsprm.cxx 
b/writerfilter/source/rtftok/rtfsprm.cxx
index 22cdda6b4b6f..fe6af8e5e4d8 100644
--- a/writerfilter/source/rtftok/rtfsprm.cxx
+++ b/writerfilter/source/rtftok/rtfsprm.cxx
@@ -40,7 +40,7 @@ std::string RTFSprm::toString() const
 {
     OStringBuffer aBuf("RTFSprm");
 
-    std::string sResult = (*QNameToString::Instance())(m_nKeyword);
+    std::string sResult = QNameToString(m_nKeyword);
 
     aBuf.append(" ('");
     if (sResult.length() == 0)
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to