summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Stedfast <jeff@xamarin.com>2014-07-26 13:51:59 -0400
committerMichael Meeks <michael.meeks@collabora.com>2014-07-26 13:52:54 -0400
commitb3d434a9701daab054981c891c645eefe1685b51 (patch)
tree485c379a0cd89eb6364f335b5efdb8345d8d0d34
parent77b74fe9def6fa37d09600e81f9d88c3a3b4293b (diff)
fdo#80908 - avoid lots of alloc/free of 2x boolean values.
Change-Id: I04c680813e997b98d8c1aae70953a61e5c28c4cd
-rw-r--r--writerfilter/source/ooxml/OOXMLFactory.cxx2
-rw-r--r--writerfilter/source/ooxml/OOXMLFastContextHandler.cxx8
-rw-r--r--writerfilter/source/ooxml/OOXMLPropertySetImpl.cxx28
-rw-r--r--writerfilter/source/ooxml/OOXMLPropertySetImpl.hxx3
4 files changed, 30 insertions, 11 deletions
diff --git a/writerfilter/source/ooxml/OOXMLFactory.cxx b/writerfilter/source/ooxml/OOXMLFactory.cxx
index eb5e4b43f864..7546096a588b 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 c66d190c4e21..be6319fda578 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 4061de2c59df..258922571424 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 96197b625241..bade78458b61 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();