[Libreoffice-commits] core.git: Branch 'feature/perfwork' - sax/source

Matúš Kukan matus.kukan at collabora.com
Fri Oct 3 05:47:54 PDT 2014


 sax/source/tools/fastserializer.cxx |   24 ++++++++++++++++++++++--
 sax/source/tools/fastserializer.hxx |    5 +++++
 sax/source/tools/fshelper.cxx       |    2 +-
 3 files changed, 28 insertions(+), 3 deletions(-)

New commits:
commit 4a0b656701ff863dfc0ab4d2c3cdedb798a572d7
Author: Matúš Kukan <matus.kukan at collabora.com>
Date:   Fri Oct 3 12:30:51 2014 +0200

    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

diff --git a/sax/source/tools/fastserializer.cxx b/sax/source/tools/fastserializer.cxx
index 3876609..cd8b0ca 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 60ef71b..5b740ce 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 801be10..15a5efa 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;
 }
 


More information about the Libreoffice-commits mailing list