[Libreoffice-commits] core.git: sax/source
Noel Grandin (via logerrit)
logerrit at kemper.freedesktop.org
Thu Apr 2 18:06:29 UTC 2020
sax/source/expatwrap/sax_expat.cxx | 32 +++++-----
sax/source/expatwrap/xml2utf.cxx | 65 ++++++++++-----------
sax/source/fastparser/fastparser.cxx | 65 ++++++++++-----------
sax/source/fastparser/legacyfastparser.cxx | 88 ++++++++++++++---------------
sax/source/tools/fastserializer.cxx | 30 ++++-----
5 files changed, 139 insertions(+), 141 deletions(-)
New commits:
commit d8af42ec5004c8cdb57b6aa60a0f811cf61ad355
Author: Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Thu Apr 2 10:52:17 2020 +0200
Commit: Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Thu Apr 2 20:05:51 2020 +0200
loplugin:flatten in sax
Change-Id: I01c1f3328d04cf6ea7c76fab9547970387b968e5
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/91551
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
diff --git a/sax/source/expatwrap/sax_expat.cxx b/sax/source/expatwrap/sax_expat.cxx
index 3172fbe89503..b80ebf033782 100644
--- a/sax/source/expatwrap/sax_expat.cxx
+++ b/sax/source/expatwrap/sax_expat.cxx
@@ -699,25 +699,25 @@ void SaxExpatParser_Impl::callbackStartElement( void *pvThis ,
{
SaxExpatParser_Impl *pImpl = static_cast<SaxExpatParser_Impl*>(pvThis);
- if( pImpl->rDocumentHandler.is() ) {
-
- int i = 0;
- pImpl->rAttrList->Clear();
+ if( !pImpl->rDocumentHandler.is() )
+ return;
- while( awAttributes[i] ) {
- assert(awAttributes[i+1]);
- pImpl->rAttrList->AddAttribute(
- XML_CHAR_TO_OUSTRING( awAttributes[i] ) ,
- gsCDATA, // expat doesn't know types
- XML_CHAR_TO_OUSTRING( awAttributes[i+1] ) );
- i +=2;
- }
+ int i = 0;
+ pImpl->rAttrList->Clear();
- CALL_ELEMENT_HANDLER_AND_CARE_FOR_EXCEPTIONS(
- pImpl ,
- rDocumentHandler->startElement( XML_CHAR_TO_OUSTRING( pwName ) ,
- pImpl->rAttrList.get() ) );
+ while( awAttributes[i] ) {
+ assert(awAttributes[i+1]);
+ pImpl->rAttrList->AddAttribute(
+ XML_CHAR_TO_OUSTRING( awAttributes[i] ) ,
+ gsCDATA, // expat doesn't know types
+ XML_CHAR_TO_OUSTRING( awAttributes[i+1] ) );
+ i +=2;
}
+
+ CALL_ELEMENT_HANDLER_AND_CARE_FOR_EXCEPTIONS(
+ pImpl ,
+ rDocumentHandler->startElement( XML_CHAR_TO_OUSTRING( pwName ) ,
+ pImpl->rAttrList.get() ) );
}
void SaxExpatParser_Impl::callbackEndElement( void *pvThis , const XML_Char *pwName )
diff --git a/sax/source/expatwrap/xml2utf.cxx b/sax/source/expatwrap/xml2utf.cxx
index 3e318d8827c3..420f90b6c3f0 100644
--- a/sax/source/expatwrap/xml2utf.cxx
+++ b/sax/source/expatwrap/xml2utf.cxx
@@ -117,43 +117,42 @@ sal_Int32 XMLFile2UTFConverter::readAndConvert( Sequence<sal_Int8> &seq , sal_In
void XMLFile2UTFConverter::removeEncoding( Sequence<sal_Int8> &seq )
{
const sal_Int8 *pSource = seq.getArray();
- if (seq.getLength() >= 5 && !strncmp(reinterpret_cast<const char *>(pSource), "<?xml", 5))
- {
+ if (!(seq.getLength() >= 5 && !strncmp(reinterpret_cast<const char *>(pSource), "<?xml", 5)))
+ return;
- // scan for encoding
- OString str( reinterpret_cast<char const *>(pSource), seq.getLength() );
+ // scan for encoding
+ OString str( reinterpret_cast<char const *>(pSource), seq.getLength() );
- // cut sequence to first line break
- // find first line break;
- int nMax = str.indexOf( 10 );
- if( nMax >= 0 )
- {
- str = str.copy( 0 , nMax );
- }
+ // cut sequence to first line break
+ // find first line break;
+ int nMax = str.indexOf( 10 );
+ if( nMax >= 0 )
+ {
+ str = str.copy( 0 , nMax );
+ }
- int nFound = str.indexOf( " encoding" );
- if( nFound >= 0 ) {
- int nStop;
- int nStart = str.indexOf( "\"" , nFound );
- if( nStart < 0 || str.indexOf( "'" , nFound ) < nStart )
- {
- nStart = str.indexOf( "'" , nFound );
- nStop = str.indexOf( "'" , nStart +1 );
- }
- else
- {
- nStop = str.indexOf( "\"" , nStart +1);
- }
+ int nFound = str.indexOf( " encoding" );
+ if( nFound < 0 ) return;
- if( nStart >= 0 && nStop >= 0 && nStart+1 < nStop )
- {
- // remove encoding tag from file
- memmove( &( seq.getArray()[nFound] ) ,
- &( seq.getArray()[nStop+1]) ,
- seq.getLength() - nStop -1);
- seq.realloc( seq.getLength() - ( nStop+1 - nFound ) );
- }
- }
+ int nStop;
+ int nStart = str.indexOf( "\"" , nFound );
+ if( nStart < 0 || str.indexOf( "'" , nFound ) < nStart )
+ {
+ nStart = str.indexOf( "'" , nFound );
+ nStop = str.indexOf( "'" , nStart +1 );
+ }
+ else
+ {
+ nStop = str.indexOf( "\"" , nStart +1);
+ }
+
+ if( nStart >= 0 && nStop >= 0 && nStart+1 < nStop )
+ {
+ // remove encoding tag from file
+ memmove( &( seq.getArray()[nFound] ) ,
+ &( seq.getArray()[nStop+1]) ,
+ seq.getLength() - nStop -1);
+ seq.realloc( seq.getLength() - ( nStop+1 - nFound ) );
}
}
diff --git a/sax/source/fastparser/fastparser.cxx b/sax/source/fastparser/fastparser.cxx
index 81591e4a3649..bca3f502defc 100644
--- a/sax/source/fastparser/fastparser.cxx
+++ b/sax/source/fastparser/fastparser.cxx
@@ -943,26 +943,26 @@ void FastSaxParserImpl::deleteUsedEvents()
void FastSaxParserImpl::produce( bool bForceFlush )
{
Entity& rEntity = getEntity();
- if (bForceFlush ||
- rEntity.mnProducedEventsSize >= Entity::mnEventListSize)
- {
- osl::ResettableMutexGuard aGuard(rEntity.maEventProtector);
-
- while (rEntity.maPendingEvents.size() >= Entity::mnEventHighWater)
- { // pause parsing for a bit
- aGuard.clear(); // unlock
- rEntity.maProduceResume.wait();
- rEntity.maProduceResume.reset();
- aGuard.reset(); // lock
- }
+ if (!(bForceFlush ||
+ rEntity.mnProducedEventsSize >= Entity::mnEventListSize))
+ return;
- rEntity.maPendingEvents.push(std::move(rEntity.mxProducedEvents));
- assert(rEntity.mxProducedEvents.get() == nullptr);
+ osl::ResettableMutexGuard aGuard(rEntity.maEventProtector);
+ while (rEntity.maPendingEvents.size() >= Entity::mnEventHighWater)
+ { // pause parsing for a bit
aGuard.clear(); // unlock
-
- rEntity.maConsumeResume.set();
+ rEntity.maProduceResume.wait();
+ rEntity.maProduceResume.reset();
+ aGuard.reset(); // lock
}
+
+ rEntity.maPendingEvents.push(std::move(rEntity.mxProducedEvents));
+ assert(rEntity.mxProducedEvents.get() == nullptr);
+
+ aGuard.clear(); // unlock
+
+ rEntity.maConsumeResume.set();
}
bool FastSaxParserImpl::consume(EventList& rEventList)
@@ -1348,23 +1348,22 @@ FastSaxParser::~FastSaxParser()
void SAL_CALL
FastSaxParser::initialize(css::uno::Sequence< css::uno::Any > const& rArguments)
{
- if (rArguments.hasElements())
- {
- OUString str;
- if ( rArguments[0] >>= str )
- {
- if ( str == "IgnoreMissingNSDecl" )
- mpImpl->m_bIgnoreMissingNSDecl = true;
- else if ( str == "DoSmeplease" )
- ; //just ignore as this is already immune to billion laughs
- else if ( str == "DisableThreadedParser" )
- mpImpl->m_bDisableThreadedParser = true;
- else
- throw IllegalArgumentException();
- }
- else
- throw IllegalArgumentException();
- }
+ if (!rArguments.hasElements())
+ return;
+
+ OUString str;
+ if ( !(rArguments[0] >>= str) )
+ throw IllegalArgumentException();
+
+ if ( str == "IgnoreMissingNSDecl" )
+ mpImpl->m_bIgnoreMissingNSDecl = true;
+ else if ( str == "DoSmeplease" )
+ ; //just ignore as this is already immune to billion laughs
+ else if ( str == "DisableThreadedParser" )
+ mpImpl->m_bDisableThreadedParser = true;
+ else
+ throw IllegalArgumentException();
+
}
void FastSaxParser::parseStream( const xml::sax::InputSource& aInputSource )
diff --git a/sax/source/fastparser/legacyfastparser.cxx b/sax/source/fastparser/legacyfastparser.cxx
index 6b11fbb3754a..bb1045970e73 100644
--- a/sax/source/fastparser/legacyfastparser.cxx
+++ b/sax/source/fastparser/legacyfastparser.cxx
@@ -220,34 +220,34 @@ void SAL_CALL CallbackDocumentHandler::startFastElement( sal_Int32 nElement , co
void SAL_CALL CallbackDocumentHandler::startUnknownElement( const OUString& /*Namespace*/, const OUString& Name, const Reference< XFastAttributeList >& Attribs )
{
- if ( m_xDocumentHandler.is() )
- {
- rtl::Reference < comphelper::AttributeList > rAttrList = new comphelper::AttributeList;
- m_aNamespaceHandler->addNSDeclAttributes( rAttrList );
+ if ( !m_xDocumentHandler.is() )
+ return;
- const Sequence< xml::FastAttribute > fastAttribs = Attribs->getFastAttributes();
- for (const auto& rAttr : fastAttribs)
- {
- const OUString& rAttrValue = rAttr.Value;
- sal_Int32 nToken = rAttr.Token;
- const OUString& rAttrNamespacePrefix = CallbackDocumentHandler::getNamespacePrefixFromToken( nToken );
- OUString sAttrName = CallbackDocumentHandler::getNameFromToken( nToken );
- if ( !rAttrNamespacePrefix.isEmpty() )
- sAttrName = rAttrNamespacePrefix + aNamespaceSeparator + sAttrName;
-
- rAttrList->AddAttribute( sAttrName, "CDATA", rAttrValue );
- }
+ rtl::Reference < comphelper::AttributeList > rAttrList = new comphelper::AttributeList;
+ m_aNamespaceHandler->addNSDeclAttributes( rAttrList );
- const Sequence< xml::Attribute > unknownAttribs = Attribs->getUnknownAttributes();
- for (const auto& rAttr : unknownAttribs)
- {
- const OUString& rAttrValue = rAttr.Value;
- const OUString& rAttrName = rAttr.Name;
+ const Sequence< xml::FastAttribute > fastAttribs = Attribs->getFastAttributes();
+ for (const auto& rAttr : fastAttribs)
+ {
+ const OUString& rAttrValue = rAttr.Value;
+ sal_Int32 nToken = rAttr.Token;
+ const OUString& rAttrNamespacePrefix = CallbackDocumentHandler::getNamespacePrefixFromToken( nToken );
+ OUString sAttrName = CallbackDocumentHandler::getNameFromToken( nToken );
+ if ( !rAttrNamespacePrefix.isEmpty() )
+ sAttrName = rAttrNamespacePrefix + aNamespaceSeparator + sAttrName;
+
+ rAttrList->AddAttribute( sAttrName, "CDATA", rAttrValue );
+ }
- rAttrList->AddAttribute( rAttrName, "CDATA", rAttrValue );
- }
- m_xDocumentHandler->startElement( Name, rAttrList.get() );
+ const Sequence< xml::Attribute > unknownAttribs = Attribs->getUnknownAttributes();
+ for (const auto& rAttr : unknownAttribs)
+ {
+ const OUString& rAttrValue = rAttr.Value;
+ const OUString& rAttrName = rAttr.Name;
+
+ rAttrList->AddAttribute( rAttrName, "CDATA", rAttrValue );
}
+ m_xDocumentHandler->startElement( Name, rAttrList.get() );
}
void SAL_CALL CallbackDocumentHandler::endFastElement( sal_Int32 nElement )
@@ -291,30 +291,30 @@ SaxLegacyFastParser::SaxLegacyFastParser( ) : m_aNamespaceHandler( new Namespace
void SAL_CALL SaxLegacyFastParser::initialize(Sequence< Any > const& rArguments )
{
- if (rArguments.hasElements())
+ if (!rArguments.hasElements())
+ return;
+
+ Reference< XFastTokenHandler > xTokenHandler;
+ OUString str;
+ if ( ( rArguments[0] >>= xTokenHandler ) && xTokenHandler.is() )
{
- Reference< XFastTokenHandler > xTokenHandler;
- OUString str;
- if ( ( rArguments[0] >>= xTokenHandler ) && xTokenHandler.is() )
- {
- m_xTokenHandler.set( xTokenHandler );
- }
- else if ( ( rArguments[0] >>= str ) && "registerNamespaces" == str )
- {
- css::beans::Pair< OUString, sal_Int32 > rPair;
- for (sal_Int32 i = 1; i < rArguments.getLength(); i++ )
- {
- rArguments[i] >>= rPair;
- m_xParser->registerNamespace( rPair.First, rPair.Second );
- }
- }
- else
+ m_xTokenHandler.set( xTokenHandler );
+ }
+ else if ( ( rArguments[0] >>= str ) && "registerNamespaces" == str )
+ {
+ css::beans::Pair< OUString, sal_Int32 > rPair;
+ for (sal_Int32 i = 1; i < rArguments.getLength(); i++ )
{
- uno::Reference<lang::XInitialization> const xInit(m_xParser,
- uno::UNO_QUERY_THROW);
- xInit->initialize( rArguments );
+ rArguments[i] >>= rPair;
+ m_xParser->registerNamespace( rPair.First, rPair.Second );
}
}
+ else
+ {
+ uno::Reference<lang::XInitialization> const xInit(m_xParser,
+ uno::UNO_QUERY_THROW);
+ xInit->initialize( rArguments );
+ }
}
void SaxLegacyFastParser::parseStream( const InputSource& structSource )
diff --git a/sax/source/tools/fastserializer.cxx b/sax/source/tools/fastserializer.cxx
index 5a846cf516b7..202641999b78 100644
--- a/sax/source/tools/fastserializer.cxx
+++ b/sax/source/tools/fastserializer.cxx
@@ -726,22 +726,22 @@ namespace sax_fastparser {
void FastSaxSerializer::ForMerge::merge( Int8Sequence &rTop, const Int8Sequence &rMerge, bool bAppend )
{
sal_Int32 nMergeLen = rMerge.getLength();
- if ( nMergeLen > 0 )
- {
- sal_Int32 nTopLen = rTop.getLength();
+ if ( nMergeLen <= 0 )
+ return;
- rTop.realloc( nTopLen + nMergeLen );
- if ( bAppend )
- {
- // append the rMerge to the rTop
- memcpy( rTop.getArray() + nTopLen, rMerge.getConstArray(), nMergeLen );
- }
- else
- {
- // prepend the rMerge to the rTop
- memmove( rTop.getArray() + nMergeLen, rTop.getConstArray(), nTopLen );
- memcpy( rTop.getArray(), rMerge.getConstArray(), nMergeLen );
- }
+ sal_Int32 nTopLen = rTop.getLength();
+
+ rTop.realloc( nTopLen + nMergeLen );
+ if ( bAppend )
+ {
+ // append the rMerge to the rTop
+ memcpy( rTop.getArray() + nTopLen, rMerge.getConstArray(), nMergeLen );
+ }
+ else
+ {
+ // prepend the rMerge to the rTop
+ memmove( rTop.getArray() + nMergeLen, rTop.getConstArray(), nTopLen );
+ memcpy( rTop.getArray(), rMerge.getConstArray(), nMergeLen );
}
}
More information about the Libreoffice-commits
mailing list