[Libreoffice-commits] core.git: include/xmlreader xmlreader/source

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Tue May 11 09:54:25 UTC 2021


 include/xmlreader/pad.hxx |    3 ++-
 xmlreader/source/pad.cxx  |   25 ++++++++++++++-----------
 2 files changed, 16 insertions(+), 12 deletions(-)

New commits:
commit de5af8315e014ce3408f66c6de3c9c4e841f8437
Author:     Noel Grandin <noel at peralex.com>
AuthorDate: Mon May 10 15:38:29 2021 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Tue May 11 11:53:45 2021 +0200

    improve perf of xmlreader::Pad
    
    Change-Id: I83cc88977e7c287b0f428a3e01f289179b6dbad9
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115353
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/include/xmlreader/pad.hxx b/include/xmlreader/pad.hxx
index 3aa73d57eab4..1f758c471338 100644
--- a/include/xmlreader/pad.hxx
+++ b/include/xmlreader/pad.hxx
@@ -47,7 +47,8 @@ private:
     SAL_DLLPRIVATE void flushSpan();
 
     Span span_;
-    OStringBuffer buffer_{ 256 };
+    sal_Int32 buflength_ = 0;
+    char buffer_[1024];
 };
 }
 
diff --git a/xmlreader/source/pad.cxx b/xmlreader/source/pad.cxx
index ce45f805f496..74bb5ec63fb0 100644
--- a/xmlreader/source/pad.cxx
+++ b/xmlreader/source/pad.cxx
@@ -29,46 +29,49 @@ namespace xmlreader {
 
 void Pad::add(char const * begin, sal_Int32 length) {
     assert(
-        begin != nullptr && length >= 0 && !(span_.is() && buffer_.getLength() != 0));
+        begin != nullptr && length >= 0 && !(span_.is() && buflength_ != 0));
     if (length != 0) {
         flushSpan();
-        if (buffer_.isEmpty()) {
+        if (buflength_ == 0) {
             span_ = Span(begin, length);
         } else {
-            buffer_.append(begin, length);
+            memcpy(buffer_ + buflength_, begin, length);
+            buflength_ += length;
         }
     }
 }
 
 void Pad::addEphemeral(char const * begin, sal_Int32 length) {
     assert(
-        begin != nullptr && length >= 0 && !(span_.is() && buffer_.getLength() != 0));
+        begin != nullptr && length >= 0 && !(span_.is() && buflength_ != 0));
     if (length != 0) {
         flushSpan();
-        buffer_.append(begin, length);
+        memcpy(buffer_ + buflength_, begin, length);
+        buflength_ += length;
     }
 }
 
 void Pad::clear() {
-    assert(!(span_.is() && buffer_.getLength() != 0));
+    assert(!(span_.is() && buflength_ != 0));
     span_.clear();
-    buffer_.setLength(0);
+    buflength_ = 0;
 }
 
 Span Pad::get() const {
-    assert(!(span_.is() && buffer_.getLength() != 0));
+    assert(!(span_.is() && buflength_ != 0));
     if (span_.is()) {
         return span_;
-    } else if (buffer_.isEmpty()) {
+    } else if (buflength_ == 0) {
         return Span("");
     } else {
-        return Span(buffer_.getStr(), buffer_.getLength());
+        return Span(buffer_, buflength_);
     }
 }
 
 void Pad::flushSpan() {
     if (span_.is()) {
-        buffer_.append(span_.begin, span_.length);
+        memcpy(buffer_ + buflength_, span_.begin, span_.length);
+        buflength_ += span_.length;
         span_.clear();
     }
 }


More information about the Libreoffice-commits mailing list