summaryrefslogtreecommitdiff
path: root/sax
diff options
context:
space:
mode:
authorMatúš Kukan <matus.kukan@collabora.com>2014-10-03 12:30:51 +0200
committerMatúš Kukan <matus.kukan@collabora.com>2014-10-23 14:30:28 +0200
commitf89cace61aebe2d567ea3bd0dfb89cb04f3490c2 (patch)
tree829ab535dde2bb5b96078e8e3695ca389d62d44e /sax
parent03040ac23be13d8bbcee9f5be3d21979d7705a0e (diff)
FastSerializer: Avoid some cycles when dealing with doubles
Would be easier to use OStringBuffer, but we can't get its pData member. Also its append(double) is suboptimal (or anything that uses rtl_str_valueOfDouble) - should be doing something like this commit. Change-Id: I8f3140081a574a84f0e60dc85cce1bd2de23cd34
Diffstat (limited to 'sax')
-rw-r--r--sax/source/tools/fastserializer.cxx24
-rw-r--r--sax/source/tools/fastserializer.hxx5
-rw-r--r--sax/source/tools/fshelper.cxx2
3 files changed, 28 insertions, 3 deletions
diff --git a/sax/source/tools/fastserializer.cxx b/sax/source/tools/fastserializer.cxx
index 38766095e5fc..cd8b0caed9c4 100644
--- a/sax/source/tools/fastserializer.cxx
+++ b/sax/source/tools/fastserializer.cxx
@@ -20,7 +20,7 @@
#include "fastserializer.hxx"
#include <com/sun/star/xml/sax/FastTokenHandler.hpp>
-#include <rtl/ustrbuf.hxx>
+#include <rtl/math.hxx>
#include <comphelper/processfactory.hxx>
#include <comphelper/sequenceasvector.hxx>
@@ -66,19 +66,39 @@ namespace sax_fastparser {
FastSaxSerializer::FastSaxSerializer( const css::uno::Reference< css::io::XOutputStream >& xOutputStream )
: maCachedOutputStream()
, maMarkStack()
+ , mpDoubleStr(NULL)
+ , mnDoubleStrCapacity(RTL_STR_MAX_VALUEOFDOUBLE)
{
+ rtl_string_new_WithLength(&mpDoubleStr, mnDoubleStrCapacity);
mxFastTokenHandler = css::xml::sax::FastTokenHandler::create(
::comphelper::getProcessComponentContext());
assert(xOutputStream.is()); // cannot do anything without that
maCachedOutputStream.setOutputStream( xOutputStream );
}
- FastSaxSerializer::~FastSaxSerializer() {}
+
+ FastSaxSerializer::~FastSaxSerializer()
+ {
+ rtl_string_release(mpDoubleStr);
+ }
void FastSaxSerializer::startDocument()
{
writeBytes(sXmlHeader, N_CHARS(sXmlHeader));
}
+ void FastSaxSerializer::write( double value )
+ {
+ rtl_math_doubleToString(
+ &mpDoubleStr, &mnDoubleStrCapacity, 0, value, rtl_math_StringFormat_G,
+ RTL_STR_MAX_VALUEOFDOUBLE - RTL_CONSTASCII_LENGTH("-x.E-xxx"), '.', 0,
+ 0, sal_True);
+
+ write(mpDoubleStr->buffer, mpDoubleStr->length);
+ // and "clear" the string
+ mpDoubleStr->length = 0;
+ mnDoubleStrCapacity = RTL_STR_MAX_VALUEOFDOUBLE;
+ }
+
void FastSaxSerializer::write( const OUString& sOutput, bool bEscape )
{
if (!lcl_isAscii(sOutput))
diff --git a/sax/source/tools/fastserializer.hxx b/sax/source/tools/fastserializer.hxx
index 60ef71bb59b7..5b740cee338b 100644
--- a/sax/source/tools/fastserializer.hxx
+++ b/sax/source/tools/fastserializer.hxx
@@ -110,6 +110,7 @@ public:
void writeId( ::sal_Int32 Element );
OString getId( ::sal_Int32 Element );
+ void write( double value );
void write( const OUString& s, bool bEscape = false );
void write( const OString& s, bool bEscape = false );
void write( const char* pStr, sal_Int32 nLen, bool bEscape = false );
@@ -204,6 +205,10 @@ private:
};
::std::stack< boost::shared_ptr< ForMerge > > maMarkStack;
+ // Would be better to use OStringBuffer instead of these two
+ // but then we couldn't get the rtl_String* member :-(
+ rtl_String *mpDoubleStr;
+ sal_Int32 mnDoubleStrCapacity;
TokenValueList maTokenValues;
#ifdef DBG_UTIL
diff --git a/sax/source/tools/fshelper.cxx b/sax/source/tools/fshelper.cxx
index 801be108bc07..15a5efa0f518 100644
--- a/sax/source/tools/fshelper.cxx
+++ b/sax/source/tools/fshelper.cxx
@@ -126,7 +126,7 @@ FastSerializerHelper* FastSerializerHelper::write(sal_Int64 value)
FastSerializerHelper* FastSerializerHelper::write(double value)
{
- mpSerializer->write(OString::number(value));
+ mpSerializer->write(value);
return this;
}