summaryrefslogtreecommitdiff
path: root/sax
diff options
context:
space:
mode:
authorMatúš Kukan <matus.kukan@gmail.com>2013-10-08 12:42:21 +0200
committerMatúš Kukan <matus.kukan@gmail.com>2013-10-17 21:38:35 +0200
commitbd4c869bbb66839506a45b71ab64792289ac7256 (patch)
treec9d8ab3cd1b5babace5c7fc26435b392c5272579 /sax
parent7e77559b6f79dbf7e96073ac5a90f9b8ff0270c9 (diff)
fastparser: store mnNamespaceCount in another stack
This is preparation work for multithreading. mnNamespaceCount will be handled in parser thread and the rest in main thread. Change-Id: I571026ea499f6876b8dafb4e1bdc56d1add649e5
Diffstat (limited to 'sax')
-rw-r--r--sax/source/fastparser/fastparser.cxx27
-rw-r--r--sax/source/fastparser/fastparser.hxx2
2 files changed, 17 insertions, 12 deletions
diff --git a/sax/source/fastparser/fastparser.cxx b/sax/source/fastparser/fastparser.cxx
index cc1134b63cdf..623638a1a9dd 100644
--- a/sax/source/fastparser/fastparser.cxx
+++ b/sax/source/fastparser/fastparser.cxx
@@ -46,13 +46,12 @@ namespace sax_fastparser {
struct SaxContextImpl
{
Reference< XFastContextHandler > mxContext;
- sal_uInt32 mnNamespaceCount;
sal_Int32 mnElementToken;
OUString maNamespace;
OUString maElementName;
- SaxContextImpl() { mnNamespaceCount = 0; mnElementToken = 0; }
- SaxContextImpl( const SaxContextImplPtr& p ) { mnNamespaceCount = p->mnNamespaceCount; mnElementToken = p->mnElementToken; maNamespace = p->maNamespace; }
+ SaxContextImpl() { mnElementToken = 0; }
+ SaxContextImpl( const SaxContextImplPtr& p ) { mnElementToken = p->mnElementToken; maNamespace = p->maNamespace; }
};
// --------------------------------------------------------------------
@@ -220,11 +219,13 @@ void FastSaxParser::pushContext()
if( rEntity.maContextStack.empty() )
{
rEntity.maContextStack.push( SaxContextImplPtr( new SaxContextImpl ) );
+ rEntity.maNamespaceCount.push(0);
DefineNamespace( OString("xml"), "http://www.w3.org/XML/1998/namespace");
}
else
{
rEntity.maContextStack.push( SaxContextImplPtr( new SaxContextImpl( rEntity.maContextStack.top() ) ) );
+ rEntity.maNamespaceCount.push( rEntity.maNamespaceCount.top() );
}
}
@@ -236,6 +237,8 @@ void FastSaxParser::popContext()
assert(!rEntity.maContextStack.empty()); // pop without push?
if( !rEntity.maContextStack.empty() )
rEntity.maContextStack.pop();
+ if( !rEntity.maNamespaceCount.empty() )
+ rEntity.maNamespaceCount.pop();
}
// --------------------------------------------------------------------
@@ -243,10 +246,10 @@ void FastSaxParser::popContext()
void FastSaxParser::DefineNamespace( const OString& rPrefix, const sal_Char* pNamespaceURL )
{
Entity& rEntity = getEntity();
- assert(!rEntity.maContextStack.empty()); // need a context!
- if( !rEntity.maContextStack.empty() )
+ assert(!rEntity.maNamespaceCount.empty()); // need a context!
+ if( !rEntity.maNamespaceCount.empty() )
{
- sal_uInt32 nOffset = rEntity.maContextStack.top()->mnNamespaceCount++;
+ sal_uInt32 nOffset = rEntity.maNamespaceCount.top()++;
if( rEntity.maNamespaceDefines.size() <= nOffset )
rEntity.maNamespaceDefines.resize( rEntity.maNamespaceDefines.size() + 64 );
@@ -299,7 +302,7 @@ sal_Int32 FastSaxParser::GetTokenWithPrefix( const OString& rPrefix, const OStri
sal_Int32 nNamespaceToken = FastToken::DONTKNOW;
Entity& rEntity = getEntity();
- sal_uInt32 nNamespace = rEntity.maContextStack.top()->mnNamespaceCount;
+ sal_uInt32 nNamespace = rEntity.maNamespaceCount.top();
while( nNamespace-- )
{
if( rEntity.maNamespaceDefines[nNamespace]->maPrefix == rPrefix )
@@ -327,7 +330,7 @@ sal_Int32 FastSaxParser::GetTokenWithPrefix( const sal_Char*pPrefix, int nPrefix
sal_Int32 nNamespaceToken = FastToken::DONTKNOW;
Entity& rEntity = getEntity();
- sal_uInt32 nNamespace = rEntity.maContextStack.top()->mnNamespaceCount;
+ sal_uInt32 nNamespace = rEntity.maNamespaceCount.top();
while( nNamespace-- )
{
const OString& rPrefix( rEntity.maNamespaceDefines[nNamespace]->maPrefix );
@@ -368,9 +371,9 @@ sal_Int32 FastSaxParser::GetNamespaceToken( const OUString& rNamespaceURL )
OUString FastSaxParser::GetNamespaceURL( const OString& rPrefix ) throw (SAXException)
{
Entity& rEntity = getEntity();
- if( !rEntity.maContextStack.empty() )
+ if( !rEntity.maNamespaceCount.empty() )
{
- sal_uInt32 nNamespace = rEntity.maContextStack.top()->mnNamespaceCount;
+ sal_uInt32 nNamespace = rEntity.maNamespaceCount.top();
while( nNamespace-- )
if( rEntity.maNamespaceDefines[nNamespace]->maPrefix == rPrefix )
return rEntity.maNamespaceDefines[nNamespace]->maNamespaceURL;
@@ -382,9 +385,9 @@ OUString FastSaxParser::GetNamespaceURL( const OString& rPrefix ) throw (SAXExce
OUString FastSaxParser::GetNamespaceURL( const sal_Char*pPrefix, int nPrefixLen ) throw(SAXException)
{
Entity& rEntity = getEntity();
- if( pPrefix && !rEntity.maContextStack.empty() )
+ if( pPrefix && !rEntity.maNamespaceCount.empty() )
{
- sal_uInt32 nNamespace = rEntity.maContextStack.top()->mnNamespaceCount;
+ sal_uInt32 nNamespace = rEntity.maNamespaceCount.top();
while( nNamespace-- )
{
const OString& rPrefix( rEntity.maNamespaceDefines[nNamespace]->maPrefix );
diff --git a/sax/source/fastparser/fastparser.hxx b/sax/source/fastparser/fastparser.hxx
index 6f9abae1d5b5..aa71fb0ad4d9 100644
--- a/sax/source/fastparser/fastparser.hxx
+++ b/sax/source/fastparser/fastparser.hxx
@@ -80,6 +80,8 @@ struct Entity : public ParserData
::com::sun::star::uno::Any maSavedException;
::std::stack< SaxContextImplPtr > maContextStack;
+ // Determines which elements of maNamespaceDefines are valid in current context
+ ::std::stack< sal_uInt32 > maNamespaceCount;
::std::vector< NamespaceDefineRef > maNamespaceDefines;
explicit Entity( const ParserData& rData );