summaryrefslogtreecommitdiff
path: root/sax
diff options
context:
space:
mode:
authorMatúš Kukan <matus.kukan@collabora.com>2014-10-01 12:50:29 +0200
committerMatúš Kukan <matus.kukan@collabora.com>2014-10-23 13:24:25 +0200
commitd8af144254b8f10fe1faa40f9072aad043ca35fe (patch)
tree031adbd9984ed72ee31e7c0ce49ae2257daa2614 /sax
parenteb195bbe34f1d7b794c2927e2e7053404758bc44 (diff)
FastSerializer: Use faster TokenValue struct when possible
Saves another ~100m pcycles for 650k calls in startElementInternal() Change-Id: I190326edc7feffb900e91fa7e5c3530b5b267f59
Diffstat (limited to 'sax')
-rw-r--r--sax/source/tools/fastserializer.cxx38
-rw-r--r--sax/source/tools/fastserializer.hxx20
-rw-r--r--sax/source/tools/fshelper.cxx13
3 files changed, 58 insertions, 13 deletions
diff --git a/sax/source/tools/fastserializer.cxx b/sax/source/tools/fastserializer.cxx
index 87c317c86dc5..6d46cdaa54d3 100644
--- a/sax/source/tools/fastserializer.cxx
+++ b/sax/source/tools/fastserializer.cxx
@@ -158,7 +158,10 @@ namespace sax_fastparser {
writeBytes(sOpeningBracket, N_CHARS(sOpeningBracket));
writeId(Element);
- writeFastAttributeList(pAttrList);
+ if (pAttrList)
+ writeFastAttributeList(pAttrList);
+ else
+ writeTokenValueList();
writeBytes(sClosingBracket, N_CHARS(sClosingBracket));
}
@@ -187,7 +190,10 @@ namespace sax_fastparser {
writeBytes(sOpeningBracket, N_CHARS(sOpeningBracket));
writeId(Element);
- writeFastAttributeList(pAttrList);
+ if (pAttrList)
+ writeFastAttributeList(pAttrList);
+ else
+ writeTokenValueList();
writeBytes(sSlashAndClosingBracket, N_CHARS(sSlashAndClosingBracket));
}
@@ -207,6 +213,34 @@ namespace sax_fastparser {
mxFastTokenHandler = xFastTokenHandler;
}
+ void FastSaxSerializer::writeTokenValueList()
+ {
+#ifdef DBG_UTIL
+ ::std::set<OString> DebugAttributes;
+#endif
+ for (size_t j = 0; j < maTokenValues.size(); j++)
+ {
+ writeBytes(sSpace, N_CHARS(sSpace));
+
+ sal_Int32 nToken = maTokenValues[j].nToken;
+ writeId(nToken);
+
+#ifdef DBG_UTIL
+ // Well-formedness constraint: Unique Att Spec
+ OString const nameId(getId(nToken));
+ assert(DebugAttributes.find(nameId) == DebugAttributes.end());
+ DebugAttributes.insert(nameId);
+#endif
+
+ writeBytes(sEqualSignAndQuote, N_CHARS(sEqualSignAndQuote));
+
+ write(maTokenValues[j].pValue, 0, true);
+
+ writeBytes(sQuote, N_CHARS(sQuote));
+ }
+ maTokenValues.clear();
+ }
+
void FastSaxSerializer::writeFastAttributeList( FastAttributeList* pAttrList )
{
#ifdef DBG_UTIL
diff --git a/sax/source/tools/fastserializer.hxx b/sax/source/tools/fastserializer.hxx
index 1b541c101850..6e81c910d691 100644
--- a/sax/source/tools/fastserializer.hxx
+++ b/sax/source/tools/fastserializer.hxx
@@ -33,6 +33,14 @@
namespace sax_fastparser {
+struct TokenValue
+{
+ sal_Int32 nToken;
+ const char *pValue;
+ TokenValue(sal_Int32 _nToken, const char *_pValue) : nToken(_nToken), pValue(_pValue) {}
+};
+typedef std::vector<TokenValue> TokenValueList;
+
/// Receives notification of sax document events to write into an XOutputStream.
class FastSaxSerializer
{
@@ -44,6 +52,8 @@ public:
~FastSaxSerializer();
::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > getOutputStream();
+ /// called by FSHelper to put data in for writeTokenValueList
+ TokenValueList& getTokenValueList() { return maTokenValues; }
/** called by the parser when parsing of an XML stream is started.
*/
@@ -65,12 +75,12 @@ public:
and the integer token of the namespace combined with an arithmetic
<b>or</b> operation.
- @param Attribs
+ @param pAttrList
Contains a <type>FastAttributeList</type> to access the attributes
from the element.
*/
- void startFastElement( ::sal_Int32 Element, FastAttributeList* Attribs );
+ void startFastElement( ::sal_Int32 Element, FastAttributeList* pAttrList = NULL );
/** receives notification of the end of an known element.
@see startFastElement
@@ -89,12 +99,12 @@ public:
and the integer token of the namespace combined with an arithmetic
<b>or</b> operation.
- @param Attribs
+ @param pAttrList
Contains a <type>FastAttributeList</type> to access the attributes
from the element.
*/
- void singleFastElement( ::sal_Int32 Element, FastAttributeList* Attribs );
+ void singleFastElement( ::sal_Int32 Element, FastAttributeList* pAttrList = NULL );
void setOutputStream( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& xOutputStream );
void setFastTokenHandler( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastTokenHandler >& xFastTokenHandler );
@@ -197,11 +207,13 @@ private:
};
::std::stack< boost::shared_ptr< ForMerge > > maMarkStack;
+ TokenValueList maTokenValues;
#ifdef DBG_UTIL
::std::stack<sal_Int32> m_DebugStartedElements;
#endif
+ void writeTokenValueList();
void writeFastAttributeList( FastAttributeList* pAttrList );
void writeOutput( const sal_Int8* pStr, size_t nLen );
void writeOutput( const css::uno::Sequence< ::sal_Int8 >& aData );
diff --git a/sax/source/tools/fshelper.cxx b/sax/source/tools/fshelper.cxx
index c6ac390dca19..222735207b3d 100644
--- a/sax/source/tools/fshelper.cxx
+++ b/sax/source/tools/fshelper.cxx
@@ -31,7 +31,6 @@ namespace sax_fastparser {
FastSerializerHelper::FastSerializerHelper(const Reference< io::XOutputStream >& xOutputStream, bool bWriteHeader ) :
mpSerializer(new FastSaxSerializer())
- , maAttrList(Reference< xml::sax::XFastTokenHandler >())
{
Reference< XComponentContext > xContext( ::comphelper::getProcessComponentContext(), UNO_SET_THROW );
mpSerializer->setFastTokenHandler( css::xml::sax::FastTokenHandler::create(xContext) );
@@ -51,7 +50,7 @@ void FastSerializerHelper::startElementInternal(sal_Int32 elementTokenId, ...)
{
va_list args;
va_start( args, elementTokenId );
- maAttrList.clear();
+ TokenValueList& rAttrList = mpSerializer->getTokenValueList();
while (true)
{
@@ -60,10 +59,10 @@ void FastSerializerHelper::startElementInternal(sal_Int32 elementTokenId, ...)
break;
const char* pValue = va_arg(args, const char*);
if (pValue)
- maAttrList.add(nName, pValue);
+ rAttrList.push_back(TokenValue(nName, pValue));
}
- mpSerializer->startFastElement(elementTokenId, &maAttrList);
+ mpSerializer->startFastElement(elementTokenId);
va_end( args );
}
@@ -71,7 +70,7 @@ void FastSerializerHelper::singleElementInternal(sal_Int32 elementTokenId, ...)
{
va_list args;
va_start( args, elementTokenId );
- maAttrList.clear();
+ TokenValueList& rAttrList = mpSerializer->getTokenValueList();
while (true)
{
@@ -80,10 +79,10 @@ void FastSerializerHelper::singleElementInternal(sal_Int32 elementTokenId, ...)
break;
const char* pValue = va_arg(args, const char*);
if (pValue)
- maAttrList.add(nName, pValue);
+ rAttrList.push_back(TokenValue(nName, pValue));
}
- mpSerializer->singleFastElement(elementTokenId, &maAttrList);
+ mpSerializer->singleFastElement(elementTokenId);
va_end( args );
}