sax/source/fastparser/fastparser.cxx |   10 +++++-----
 sax/source/tools/fastattribs.cxx     |   24 ++++++++++++------------
 2 files changed, 17 insertions(+), 17 deletions(-)

New commits:
commit 5d8ac865bf32f37487c02a89c00d02cd3234ce1f
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Wed Jul 6 14:50:17 2022 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Wed Jul 6 15:49:28 2022 +0200

    micro-optimisation in FastAttributeList
    
    Change-Id: If684357b8849258af213f06a52f71ea81ffac1e1
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136844
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sax/source/tools/fastattribs.cxx b/sax/source/tools/fastattribs.cxx
index 9b309d5fb422..81dabf727ebd 100644
--- a/sax/source/tools/fastattribs.cxx
+++ b/sax/source/tools/fastattribs.cxx
@@ -181,7 +181,7 @@ sal_Bool FastAttributeList::hasAttribute( ::sal_Int32 Token 
)
 
 sal_Int32 FastAttributeList::getValueToken( ::sal_Int32 Token )
 {
-    for (size_t i = 0; i < maAttributeTokens.size(); ++i)
+    for (size_t i = 0, n = maAttributeTokens.size(); i < n; ++i)
         if (maAttributeTokens[i] == Token)
             return FastTokenHandlerBase::getTokenFromChars(
                        mpTokenHandler,
@@ -193,7 +193,7 @@ sal_Int32 FastAttributeList::getValueToken( ::sal_Int32 
Token )
 
 sal_Int32 FastAttributeList::getOptionalValueToken( ::sal_Int32 Token, 
::sal_Int32 Default )
 {
-    for (size_t i = 0; i < maAttributeTokens.size(); ++i)
+    for (size_t i = 0, n = maAttributeTokens.size(); i < n; ++i)
         if (maAttributeTokens[i] == Token)
             return FastTokenHandlerBase::getTokenFromChars(
                        mpTokenHandler,
@@ -207,14 +207,14 @@ sal_Int32 FastAttributeList::getOptionalValueToken( 
::sal_Int32 Token, ::sal_Int
 bool FastAttributeList::getAsInteger( sal_Int32 nToken, sal_Int32 &rInt) const
 {
     rInt = 0;
-    for (size_t i = 0; i < maAttributeTokens.size(); ++i)
+    for (size_t i = 0, n = maAttributeTokens.size(); i < n; ++i)
         if (maAttributeTokens[i] == nToken)
         {
-            sal_Int64 n = rtl_str_toInt64_WithLength( 
getFastAttributeValue(i), 10, AttributeValueLength(i) );
-            if (n < SAL_MIN_INT32 || n > SAL_MAX_INT32) {
-                n = 0;
+            sal_Int64 nVal = rtl_str_toInt64_WithLength( 
getFastAttributeValue(i), 10, AttributeValueLength(i) );
+            if (nVal < SAL_MIN_INT32 || nVal > SAL_MAX_INT32) {
+                nVal = 0;
             }
-            rInt = n;
+            rInt = nVal;
             return true;
         }
     return false;
@@ -232,7 +232,7 @@ sal_Int32 FastAttributeList::getAsIntegerByIndex( sal_Int32 
nTokenIndex ) const
 bool FastAttributeList::getAsDouble( sal_Int32 nToken, double &rDouble) const
 {
     rDouble = 0.0;
-    for (size_t i = 0; i < maAttributeTokens.size(); ++i)
+    for (size_t i = 0, n = maAttributeTokens.size(); i < n; ++i)
         if (maAttributeTokens[i] == nToken)
         {
             auto const p = getFastAttributeValue(i);
@@ -265,7 +265,7 @@ const char* FastAttributeList::getAsCharByIndex( sal_Int32 
nTokenIndex ) const
 
 OUString FastAttributeList::getValue( ::sal_Int32 Token )
 {
-    for (size_t i = 0; i < maAttributeTokens.size(); ++i)
+    for (size_t i = 0, n = maAttributeTokens.size(); i < n; ++i)
         if (maAttributeTokens[i] == Token)
             return OUString( getFastAttributeValue(i), 
AttributeValueLength(i), RTL_TEXTENCODING_UTF8 );
 
@@ -279,7 +279,7 @@ OUString FastAttributeList::getValueByIndex( ::sal_Int32 
nTokenIndex ) const
 
 OUString FastAttributeList::getOptionalValue( ::sal_Int32 Token )
 {
-    for (size_t i = 0; i < maAttributeTokens.size(); ++i)
+    for (size_t i = 0, n = maAttributeTokens.size(); i < n; ++i)
         if (maAttributeTokens[i] == Token)
             return OUString( getFastAttributeValue(i), 
AttributeValueLength(i), RTL_TEXTENCODING_UTF8 );
 
@@ -300,7 +300,7 @@ Sequence< FastAttribute > 
FastAttributeList::getFastAttributes(  )
 {
     Sequence< FastAttribute > aSeq( maAttributeTokens.size() );
     FastAttribute* pAttr = aSeq.getArray();
-    for (size_t i = 0; i < maAttributeTokens.size(); ++i)
+    for (size_t i = 0, n = maAttributeTokens.size(); i < n; ++i)
     {
         pAttr->Token = maAttributeTokens[i];
         pAttr->Value = OUString( getFastAttributeValue(i), 
AttributeValueLength(i), RTL_TEXTENCODING_UTF8 );
@@ -311,7 +311,7 @@ Sequence< FastAttribute > 
FastAttributeList::getFastAttributes(  )
 
 FastAttributeList::FastAttributeIter FastAttributeList::find( sal_Int32 nToken 
) const
 {
-    for (size_t i = 0; i < maAttributeTokens.size(); ++i)
+    for (size_t i = 0, n = maAttributeTokens.size(); i < n; ++i)
         if( maAttributeTokens[i] == nToken )
             return FastAttributeIter(*this, i);
     return end();
commit 67631563537623c44e5c6905e0df522ad204bfc9
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Wed Jul 6 14:50:06 2022 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Wed Jul 6 15:49:15 2022 +0200

    shave some cost off SaxContext
    
    most of the time, we can skip the ref-counting associated with these
    string fields
    
    Change-Id: I7afc1aa08f3337d7c61478eab92abc2cdd2b9d1c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136843
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sax/source/fastparser/fastparser.cxx 
b/sax/source/fastparser/fastparser.cxx
index 250078bc5054..00ea75e23c6b 100644
--- a/sax/source/fastparser/fastparser.cxx
+++ b/sax/source/fastparser/fastparser.cxx
@@ -107,16 +107,16 @@ struct SaxContext
 {
     Reference< XFastContextHandler > mxContext;
     sal_Int32 mnElementToken;
-    OUString  maNamespace;
-    OUString  maElementName;
+    std::optional<OUString>  moNamespace;
+    std::optional<OUString> moElementName;
 
     SaxContext( sal_Int32 nElementToken, const OUString& aNamespace, const 
OUString& aElementName ):
             mnElementToken(nElementToken)
     {
         if (nElementToken == FastToken::DONTKNOW)
         {
-            maNamespace = aNamespace;
-            maElementName = aElementName;
+            moNamespace = aNamespace;
+            moElementName = aElementName;
         }
     }
 };
@@ -514,7 +514,7 @@ void Entity::endElement()
             if( nElementToken != FastToken::DONTKNOW )
                 pContext->endFastElement( nElementToken );
             else
-                pContext->endUnknownElement( aContext.maNamespace, 
aContext.maElementName );
+                pContext->endUnknownElement( *aContext.moNamespace, 
*aContext.moElementName );
         }
         catch (...)
         {

Reply via email to