diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2021-10-14 00:15:11 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2021-10-14 07:40:52 +0200 |
commit | 02d225f2a46b3d531e187976d8f2c39ed390899c (patch) | |
tree | db31918ce20b15d592e4b0b6dca94a3d623b95e7 /include | |
parent | 8a017d25a62e878fdd32f189f0663b05d2ffb9cf (diff) |
Simplify JsonWriter a bit
Move ensureSpace code to json_writer.cxx, and merge with reallocBuffer.
The methods are private, and are only used in methods in the same .CXX,
so the code will get inlined as compiler decides anyway, but becomes
simpler.
Make extractDataAs* to consider the known size of the data, to avoid
calculating null-terminated size. To do that, the code is moved from
extractData to private extractDataImpl, which returns both pointer
and size.
Change-Id: I7c0e425b5c584089c6e866c31d4cfdb5e242d66b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123568
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/tools/json_writer.hxx | 15 |
1 files changed, 4 insertions, 11 deletions
diff --git a/include/tools/json_writer.hxx b/include/tools/json_writer.hxx index 45df53c61c5f..72ed59edadc5 100644 --- a/include/tools/json_writer.hxx +++ b/include/tools/json_writer.hxx @@ -17,6 +17,7 @@ #include <string> #include <string_view> +#include <utility> /** Simple JSON encoder designed specifically for LibreOfficeKit purposes. * @@ -73,7 +74,7 @@ public: /** Hands ownership of the underlying storage buffer to the caller, * after this no more document modifications may be written. */ - char* extractData(); + char* extractData() { return extractDataImpl().first; } OString extractAsOString(); std::string extractAsStdString(); @@ -85,17 +86,9 @@ private: void endArray(); void endStruct(); void addCommaBeforeField(); - void reallocBuffer(int noMoreBytesRequired); void writeEscapedOUString(const OUString& rPropVal); - - // this part inline to speed up the fast path - inline void ensureSpace(int noMoreBytesRequired) - { - assert(mpBuffer && "already extracted data"); - int currentUsed = mPos - mpBuffer; - if (currentUsed + noMoreBytesRequired >= mSpaceAllocated) - reallocBuffer(noMoreBytesRequired); - } + std::pair<char*, int> extractDataImpl(); + void ensureSpace(int noMoreBytesRequired); }; /** |