summaryrefslogtreecommitdiff
path: root/sax
diff options
context:
space:
mode:
authorMichael Meeks <michael.meeks@collabora.com>2013-11-19 20:51:35 +0000
committerMichael Meeks <michael.meeks@collabora.com>2013-11-19 20:52:50 +0000
commitfc25afaa048033940d9e1d22ec8ba31c5b3e9289 (patch)
treee5368871ba27a66cad29b50f064a819087af60d5 /sax
parent7e77efe8b8f04ba739f731e5a27b5e643fe652fa (diff)
fastparser: accelerate value tokenisation as well.
Change-Id: I99a39e91c684adb1fc92cdb466477cfa90104961
Diffstat (limited to 'sax')
-rw-r--r--sax/source/fastparser/fastparser.cxx27
-rw-r--r--sax/source/fastparser/fastparser.hxx4
-rw-r--r--sax/source/tools/fastattribs.cxx55
3 files changed, 49 insertions, 37 deletions
diff --git a/sax/source/fastparser/fastparser.cxx b/sax/source/fastparser/fastparser.cxx
index 5d64a10b5f7f..8f68051eccd1 100644
--- a/sax/source/fastparser/fastparser.cxx
+++ b/sax/source/fastparser/fastparser.cxx
@@ -348,7 +348,6 @@ Event& Entity::getEvent( CallbackType aType )
FastSaxParser::FastSaxParser()
{
mxDocumentLocator.set( new FastLocatorImpl( this ) );
- maUtf8Buffer.realloc( mnUtf8BufferSize );
}
// --------------------------------------------------------------------
@@ -381,31 +380,7 @@ void FastSaxParser::DefineNamespace( const OString& rPrefix, const sal_Char* pNa
sal_Int32 FastSaxParser::GetToken( const sal_Char* pToken, sal_Int32 nLen /* = 0 */ )
{
- sal_Int32 nRet;
-
- if( !nLen )
- nLen = strlen( pToken );
-
- if ( nLen < mnUtf8BufferSize )
- {
- // Get intimiate with the underlying sequence cf. sal/types.h
- sal_Sequence *pSeq = maUtf8Buffer.get();
-
- sal_Int32 nPreRefCount = pSeq->nRefCount;
-
- pSeq->nElements = nLen;
- memcpy( pSeq->elements, pToken, nLen );
- nRet = getEntity().mxTokenHandler->getTokenFromUTF8( maUtf8Buffer );
-
- (void)nPreRefCount; // for non-debug mode.
- assert( pSeq->nRefCount == nPreRefCount ); // callee must not take ref.
- }
- else
- {
- Sequence< sal_Int8 > aSeq( (sal_Int8*)pToken, nLen ); // heap allocate & free
- nRet = getEntity().mxTokenHandler->getTokenFromUTF8( aSeq );
- }
- return nRet;
+ return maTokenLookup.getTokenFromChars( getEntity().mxTokenHandler, pToken, nLen );
}
// --------------------------------------------------------------------
diff --git a/sax/source/fastparser/fastparser.hxx b/sax/source/fastparser/fastparser.hxx
index 972ce07f542e..35deb0c76b5e 100644
--- a/sax/source/fastparser/fastparser.hxx
+++ b/sax/source/fastparser/fastparser.hxx
@@ -222,9 +222,7 @@ private:
ParserData maData; /// Cached parser configuration for next call of parseStream().
::std::stack< Entity > maEntities; /// Entity stack for each call of parseStream().
-
- static const int mnUtf8BufferSize = 128;
- ::css::uno::Sequence< sal_Int8 > maUtf8Buffer; /// avoid constantly re-allocating this
+ FastTokenLookup maTokenLookup;
};
}
diff --git a/sax/source/tools/fastattribs.cxx b/sax/source/tools/fastattribs.cxx
index 3ebab237b411..c0a92a1767aa 100644
--- a/sax/source/tools/fastattribs.cxx
+++ b/sax/source/tools/fastattribs.cxx
@@ -114,10 +114,9 @@ sal_Int32 FastAttributeList::getValueToken( ::sal_Int32 Token ) throw (SAXExcept
{
for (size_t i = 0; i < maAttributeTokens.size(); ++i)
if (maAttributeTokens[i] == Token)
- {
- Sequence< sal_Int8 > aSeq( (sal_Int8*) mpChunk + maAttributeValues[i], AttributeValueLength(i) );
- return mxTokenHandler->getTokenFromUTF8( aSeq );
- }
+ return maTokenLookup.getTokenFromChars( mxTokenHandler,
+ mpChunk + maAttributeValues[ i ],
+ AttributeValueLength( i ) );
throw SAXException();
}
@@ -126,10 +125,9 @@ sal_Int32 FastAttributeList::getOptionalValueToken( ::sal_Int32 Token, ::sal_Int
{
for (size_t i = 0; i < maAttributeTokens.size(); ++i)
if (maAttributeTokens[i] == Token)
- {
- Sequence< sal_Int8 > aSeq( (sal_Int8*) mpChunk + maAttributeValues[i], AttributeValueLength(i) );
- return mxTokenHandler->getTokenFromUTF8( aSeq );
- }
+ return maTokenLookup.getTokenFromChars( mxTokenHandler,
+ mpChunk + maAttributeValues[ i ],
+ AttributeValueLength( i ) );
return Default;
}
@@ -178,6 +176,47 @@ sal_Int32 FastAttributeList::AttributeValueLength(sal_Int32 i)
return maAttributeValues[i + 1] - maAttributeValues[i] - 1;
}
+FastTokenLookup::FastTokenLookup()
+{
+ maUtf8Buffer.realloc( mnUtf8BufferSize );
+}
+
+/**
+ * Avoid doing any memory allocation if we can, instead keep a
+ * pet sequence around and do some heavy petting on it.
+ */
+sal_Int32 FastTokenLookup::getTokenFromChars(
+ const ::css::uno::Reference< ::css::xml::sax::XFastTokenHandler > &xTokenHandler,
+ const char *pToken, size_t nLen /* = 0 */ )
+{
+ sal_Int32 nRet;
+
+ if( !nLen )
+ nLen = strlen( pToken );
+
+ if ( nLen < mnUtf8BufferSize )
+ {
+ // Get intimiate with the underlying sequence cf. sal/types.h
+ sal_Sequence *pSeq = maUtf8Buffer.get();
+
+ sal_Int32 nPreRefCount = pSeq->nRefCount;
+
+ pSeq->nElements = nLen;
+ memcpy( pSeq->elements, pToken, nLen );
+ nRet = xTokenHandler->getTokenFromUTF8( maUtf8Buffer );
+
+ (void)nPreRefCount; // for non-debug mode.
+ assert( pSeq->nRefCount == nPreRefCount ); // callee must not take ref
+ }
+ else
+ {
+ Sequence< sal_Int8 > aSeq( (sal_Int8*)pToken, nLen ); // heap allocate & free
+ nRet = xTokenHandler->getTokenFromUTF8( aSeq );
+ }
+
+ return nRet;
+}
+
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */