summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2021-05-14 15:59:46 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2021-05-14 21:31:04 +0200
commit233fa432256603812454cbdc372059afade50942 (patch)
treeb78efd6117f515057412aafe1f72f57caa1c3912
parent46d3e84d7a131f7c72cb536ab2f314cb55ffc155 (diff)
Revert "improve perf of xmlreader::Pad"
This reverts commit de5af8315e014ce3408f66c6de3c9c4e841f8437. Reason for revert: this commit needs bounds checking before it can reland Change-Id: I686a533cc27fc4644cce918ca64bd168bba19617 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115518 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r--include/xmlreader/pad.hxx3
-rw-r--r--xmlreader/source/pad.cxx25
2 files changed, 12 insertions, 16 deletions
diff --git a/include/xmlreader/pad.hxx b/include/xmlreader/pad.hxx
index 1f758c471338..3aa73d57eab4 100644
--- a/include/xmlreader/pad.hxx
+++ b/include/xmlreader/pad.hxx
@@ -47,8 +47,7 @@ private:
SAL_DLLPRIVATE void flushSpan();
Span span_;
- sal_Int32 buflength_ = 0;
- char buffer_[1024];
+ OStringBuffer buffer_{ 256 };
};
}
diff --git a/xmlreader/source/pad.cxx b/xmlreader/source/pad.cxx
index 74bb5ec63fb0..ce45f805f496 100644
--- a/xmlreader/source/pad.cxx
+++ b/xmlreader/source/pad.cxx
@@ -29,49 +29,46 @@ namespace xmlreader {
void Pad::add(char const * begin, sal_Int32 length) {
assert(
- begin != nullptr && length >= 0 && !(span_.is() && buflength_ != 0));
+ begin != nullptr && length >= 0 && !(span_.is() && buffer_.getLength() != 0));
if (length != 0) {
flushSpan();
- if (buflength_ == 0) {
+ if (buffer_.isEmpty()) {
span_ = Span(begin, length);
} else {
- memcpy(buffer_ + buflength_, begin, length);
- buflength_ += length;
+ buffer_.append(begin, length);
}
}
}
void Pad::addEphemeral(char const * begin, sal_Int32 length) {
assert(
- begin != nullptr && length >= 0 && !(span_.is() && buflength_ != 0));
+ begin != nullptr && length >= 0 && !(span_.is() && buffer_.getLength() != 0));
if (length != 0) {
flushSpan();
- memcpy(buffer_ + buflength_, begin, length);
- buflength_ += length;
+ buffer_.append(begin, length);
}
}
void Pad::clear() {
- assert(!(span_.is() && buflength_ != 0));
+ assert(!(span_.is() && buffer_.getLength() != 0));
span_.clear();
- buflength_ = 0;
+ buffer_.setLength(0);
}
Span Pad::get() const {
- assert(!(span_.is() && buflength_ != 0));
+ assert(!(span_.is() && buffer_.getLength() != 0));
if (span_.is()) {
return span_;
- } else if (buflength_ == 0) {
+ } else if (buffer_.isEmpty()) {
return Span("");
} else {
- return Span(buffer_, buflength_);
+ return Span(buffer_.getStr(), buffer_.getLength());
}
}
void Pad::flushSpan() {
if (span_.is()) {
- memcpy(buffer_ + buflength_, span_.begin, span_.length);
- buflength_ += span_.length;
+ buffer_.append(span_.begin, span_.length);
span_.clear();
}
}