diff options
author | Mohammed Abdul Azeem <azeemmysore@gmail.com> | 2017-02-07 23:53:43 +0530 |
---|---|---|
committer | Michael Meeks <michael.meeks@collabora.com> | 2017-02-08 10:49:34 +0000 |
commit | 9b724094873d0808f0bd8ddab24adc372ae4e41c (patch) | |
tree | 890bcde7477298539d13f395ed2a302e2d3dfe68 /include | |
parent | 73cc391e9c9646e09722ce4324918646202c693b (diff) |
Adding an iterator for fastattributes:
This helps to avoid the expensive allocation and
freeing of OUString at some places.
Change-Id: I7d49974ce13799fcf62b989ce5d3c61b01316190
Reviewed-on: https://gerrit.libreoffice.org/34011
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
Tested-by: Michael Meeks <michael.meeks@collabora.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/sax/fastattribs.hxx | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/include/sax/fastattribs.hxx b/include/sax/fastattribs.hxx index eeb4064e82fa..112e67801262 100644 --- a/include/sax/fastattribs.hxx +++ b/include/sax/fastattribs.hxx @@ -102,6 +102,58 @@ public: virtual css::uno::Sequence< css::xml::Attribute > SAL_CALL getUnknownAttributes( ) override; virtual css::uno::Sequence< css::xml::FastAttribute > SAL_CALL getFastAttributes() override; + /// Use for fast iteration and conversion of attributes + class FastAttributeIter { + const FastAttributeList &mrList; + size_t mnIdx; + + public: + FastAttributeIter(const FastAttributeList &rList, size_t nIdx) + : mrList(rList), mnIdx(nIdx) + { + } + + FastAttributeIter& operator++ () + { + mnIdx++; + return *this; + } + bool operator!=( const FastAttributeIter& rhs ) const + { + return mnIdx != rhs.mnIdx; + } + + sal_Int32 getToken() + { + assert(mnIdx < mrList.maAttributeTokens.size()); + return mrList.maAttributeTokens[mnIdx]; + } + bool isEmpty() + { + assert(mnIdx < mrList.maAttributeTokens.size()); + return mrList.AttributeValueLength(mnIdx) < 1; + } + sal_Int32 toInt32() + { + assert(mnIdx < mrList.maAttributeTokens.size()); + return rtl_str_toInt32(mrList.getFastAttributeValue(mnIdx), 10); + } + OUString toString() + { + assert(mnIdx < mrList.maAttributeTokens.size()); + return OUString(mrList.getFastAttributeValue(mnIdx), + mrList.AttributeValueLength(mnIdx), + RTL_TEXTENCODING_UTF8); + } + bool isString(const char *str) + { + assert(mnIdx < mrList.maAttributeTokens.size()); + return !strcmp(str, mrList.getFastAttributeValue(mnIdx)); + } + }; + const FastAttributeIter begin() const { return FastAttributeIter(*this, 0); } + const FastAttributeIter end() const { return FastAttributeIter(*this, maAttributeTokens.size()); } + private: sal_Char *mpChunk; ///< buffer to store all attribute values - null terminated strings sal_Int32 mnChunkLength; ///< size of allocated memory for mpChunk |