writerfilter/source/ooxml/OOXMLFactory.cxx            |    2 -
 writerfilter/source/ooxml/OOXMLFastContextHandler.cxx |    8 +----
 writerfilter/source/ooxml/OOXMLPropertySetImpl.cxx    |   28 ++++++++++++++----
 writerfilter/source/ooxml/OOXMLPropertySetImpl.hxx    |    3 +
 4 files changed, 30 insertions(+), 11 deletions(-)

New commits:
commit b3d434a9701daab054981c891c645eefe1685b51
Author: Jeff Stedfast <j...@xamarin.com>
Date:   Sat Jul 26 13:51:59 2014 -0400

    fdo#80908 - avoid lots of alloc/free of 2x boolean values.
    
    Change-Id: I04c680813e997b98d8c1aae70953a61e5c28c4cd

diff --git a/writerfilter/source/ooxml/OOXMLFactory.cxx 
b/writerfilter/source/ooxml/OOXMLFactory.cxx
index eb5e4b4..7546096 100644
--- a/writerfilter/source/ooxml/OOXMLFactory.cxx
+++ b/writerfilter/source/ooxml/OOXMLFactory.cxx
@@ -149,7 +149,7 @@ void OOXMLFactory::attributes(OOXMLFastContextHandler * 
pHandler,
                     {
                         const char *pValue = "";
                         pAttribs->getAsChar(nToken, pValue);
-                        OOXMLValue::Pointer_t xValue(new 
OOXMLBooleanValue(pValue));
+                        OOXMLValue::Pointer_t 
xValue(OOXMLBooleanValue::Create(pValue));
                         pHandler->newProperty(nId, xValue);
                         pFactory->attributeAction(pHandler, nToken, xValue);
                     }
diff --git a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx 
b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx
index c66d190..be6319f 100644
--- a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx
+++ b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx
@@ -1298,7 +1298,7 @@ void 
OOXMLFastContextHandlerValue::setDefaultBooleanValue()
 {
     if (mpValue.get() == NULL)
     {
-        OOXMLValue::Pointer_t pValue(new OOXMLBooleanValue(true));
+        OOXMLValue::Pointer_t pValue = OOXMLBooleanValue::Create(true);
         setValue(pValue);
     }
 }
@@ -1482,8 +1482,7 @@ void OOXMLFastContextHandlerTextTableCell::endCell()
             pProps->add(pProp);
         }
         {
-            OOXMLValue::Pointer_t pVal
-                (new OOXMLBooleanValue(mnTableDepth > 0));
+            OOXMLValue::Pointer_t pVal = 
OOXMLBooleanValue::Create(mnTableDepth > 0);
             OOXMLProperty::Pointer_t pProp
                 (new OOXMLPropertyImpl(NS_ooxml::LN_tblCell, pVal, 
OOXMLPropertyImpl::SPRM));
             pProps->add(pProp);
@@ -1582,8 +1581,7 @@ void 
OOXMLFastContextHandlerTextTableRow::handleGridBefore( OOXMLValue::Pointer_
                 pProps->add(pProp);
             }
             {
-                OOXMLValue::Pointer_t pVal
-                    (new OOXMLBooleanValue(mnTableDepth > 0));
+                OOXMLValue::Pointer_t pVal = 
OOXMLBooleanValue::Create(mnTableDepth > 0);
                 OOXMLProperty::Pointer_t pProp
                     (new OOXMLPropertyImpl(NS_ooxml::LN_tblCell, pVal, 
OOXMLPropertyImpl::SPRM));
                 pProps->add(pProp);
diff --git a/writerfilter/source/ooxml/OOXMLPropertySetImpl.cxx 
b/writerfilter/source/ooxml/OOXMLPropertySetImpl.cxx
index 4061de2..2589225 100644
--- a/writerfilter/source/ooxml/OOXMLPropertySetImpl.cxx
+++ b/writerfilter/source/ooxml/OOXMLPropertySetImpl.cxx
@@ -259,6 +259,28 @@ OOXMLValue * OOXMLBinaryValue::clone() const
   class OOXMLBooleanValue
 */
 
+static bool GetBooleanValue(const char *pValue)
+{
+    return !strcmp(pValue, "true")
+           || !strcmp(pValue, "True")
+           || !strcmp(pValue, "1")
+           || !strcmp(pValue, "on")
+           || !strcmp(pValue, "On");
+}
+
+OOXMLValue::Pointer_t OOXMLBooleanValue::Create(bool bValue)
+{
+    static OOXMLValue::Pointer_t False(new OOXMLBooleanValue (false));
+    static OOXMLValue::Pointer_t True(new OOXMLBooleanValue (true));
+
+    return bValue ? True : False;
+}
+
+OOXMLValue::Pointer_t OOXMLBooleanValue::Create(const char *pValue)
+{
+    return Create (GetBooleanValue(pValue));
+}
+
 OOXMLBooleanValue::OOXMLBooleanValue(bool bValue)
 : mbValue(bValue)
 {
@@ -267,11 +289,7 @@ OOXMLBooleanValue::OOXMLBooleanValue(bool bValue)
 OOXMLBooleanValue::OOXMLBooleanValue(const char *pValue)
 : mbValue(false)
 {
-    mbValue = !strcmp(pValue, "true")
-           || !strcmp(pValue, "True")
-           || !strcmp(pValue, "1")
-           || !strcmp(pValue, "on")
-           || !strcmp(pValue, "On");
+    mbValue = GetBooleanValue(pValue);
 }
 
 OOXMLBooleanValue::~OOXMLBooleanValue()
diff --git a/writerfilter/source/ooxml/OOXMLPropertySetImpl.hxx 
b/writerfilter/source/ooxml/OOXMLPropertySetImpl.hxx
index 96197b6..bade784 100644
--- a/writerfilter/source/ooxml/OOXMLPropertySetImpl.hxx
+++ b/writerfilter/source/ooxml/OOXMLPropertySetImpl.hxx
@@ -104,6 +104,9 @@ class OOXMLBooleanValue : public OOXMLValue
 protected:
     bool mbValue;
 public:
+    static OOXMLValue::Pointer_t Create (bool bValue);
+    static OOXMLValue::Pointer_t Create (const char *pValue);
+
     explicit OOXMLBooleanValue(bool bValue);
     explicit OOXMLBooleanValue(const char *pValue);
     virtual ~OOXMLBooleanValue();
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to