[Libreoffice-commits] core.git: include/sax sc/source

Mohammed Abdul Azeem azeemmysore at gmail.com
Wed Feb 8 10:49:57 UTC 2017


 include/sax/fastattribs.hxx       |   52 ++++++++++++++++++++++++++++++++++++
 sc/source/filter/xml/xmlbodyi.cxx |   17 ++++-------
 sc/source/filter/xml/xmlcelli.cxx |   54 ++++++++++++++++++--------------------
 sc/source/filter/xml/xmlrowi.cxx  |   17 ++++-------
 sc/source/filter/xml/xmltabi.cxx  |   23 +++++++---------
 5 files changed, 102 insertions(+), 61 deletions(-)

New commits:
commit 9b724094873d0808f0bd8ddab24adc372ae4e41c
Author: Mohammed Abdul Azeem <azeemmysore at gmail.com>
Date:   Tue Feb 7 23:53:43 2017 +0530

    Adding an iterator for fastattributes:
    
    This helps to avoid the expensive allocation and
    freeing of OUString at some places.
    
    Change-Id: I7d49974ce13799fcf62b989ce5d3c61b01316190
    Reviewed-on: https://gerrit.libreoffice.org/34011
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Michael Meeks <michael.meeks at collabora.com>
    Tested-by: Michael Meeks <michael.meeks at collabora.com>

diff --git a/include/sax/fastattribs.hxx b/include/sax/fastattribs.hxx
index eeb4064..112e678 100644
--- a/include/sax/fastattribs.hxx
+++ b/include/sax/fastattribs.hxx
@@ -102,6 +102,58 @@ public:
     virtual css::uno::Sequence< css::xml::Attribute > SAL_CALL getUnknownAttributes(  ) override;
     virtual css::uno::Sequence< css::xml::FastAttribute > SAL_CALL getFastAttributes() override;
 
+    /// Use for fast iteration and conversion of attributes
+    class FastAttributeIter {
+        const FastAttributeList &mrList;
+        size_t mnIdx;
+
+    public:
+        FastAttributeIter(const FastAttributeList &rList, size_t nIdx)
+            : mrList(rList), mnIdx(nIdx)
+        {
+        }
+
+        FastAttributeIter& operator++ ()
+        {
+            mnIdx++;
+            return *this;
+        }
+        bool operator!=( const FastAttributeIter& rhs ) const
+        {
+            return mnIdx != rhs.mnIdx;
+        }
+
+        sal_Int32 getToken()
+        {
+            assert(mnIdx < mrList.maAttributeTokens.size());
+            return mrList.maAttributeTokens[mnIdx];
+        }
+        bool isEmpty()
+        {
+            assert(mnIdx < mrList.maAttributeTokens.size());
+            return mrList.AttributeValueLength(mnIdx) < 1;
+        }
+        sal_Int32 toInt32()
+        {
+            assert(mnIdx < mrList.maAttributeTokens.size());
+            return rtl_str_toInt32(mrList.getFastAttributeValue(mnIdx), 10);
+        }
+        OUString toString()
+        {
+            assert(mnIdx < mrList.maAttributeTokens.size());
+            return OUString(mrList.getFastAttributeValue(mnIdx),
+                            mrList.AttributeValueLength(mnIdx),
+                            RTL_TEXTENCODING_UTF8);
+        }
+        bool isString(const char *str)
+        {
+            assert(mnIdx < mrList.maAttributeTokens.size());
+            return !strcmp(str, mrList.getFastAttributeValue(mnIdx));
+        }
+    };
+    const FastAttributeIter begin() const { return FastAttributeIter(*this, 0); }
+    const FastAttributeIter end() const { return FastAttributeIter(*this, maAttributeTokens.size()); }
+
 private:
     sal_Char *mpChunk; ///< buffer to store all attribute values - null terminated strings
     sal_Int32 mnChunkLength; ///< size of allocated memory for mpChunk
diff --git a/sc/source/filter/xml/xmlbodyi.cxx b/sc/source/filter/xml/xmlbodyi.cxx
index 486cea5..bb6ba3f 100644
--- a/sc/source/filter/xml/xmlbodyi.cxx
+++ b/sc/source/filter/xml/xmlbodyi.cxx
@@ -97,28 +97,25 @@ ScXMLBodyContext::ScXMLBodyContext( ScXMLImport& rImport,
     assert( dynamic_cast< sax_fastparser::FastAttributeList *>( xAttrList.get() ) != nullptr );
     pAttribList = static_cast< sax_fastparser::FastAttributeList *>( xAttrList.get() );
 
-    const std::vector< sal_Int32 >& rAttrList = pAttribList->getFastAttributeTokens();
-    for ( size_t i = 0; i < rAttrList.size(); i++ )
+    for ( auto it = pAttribList->begin(); it != pAttribList->end(); ++it)
     {
-        sal_Int32 nToken = rAttrList[ i ];
-        const OUString sValue = OUString(pAttribList->getFastAttributeValue(i),
-                                    pAttribList->AttributeValueLength(i), RTL_TEXTENCODING_UTF8);
+        sal_Int32 nToken = it.getToken();
         if( NAMESPACE_TOKEN( XML_NAMESPACE_TABLE ) == ( nToken & NMSP_MASK ) )
         {
             const sal_Int32 nLocalToken = nToken & TOKEN_MASK;
             if( nLocalToken == XML_STRUCTURE_PROTECTED )
-                bProtected = IsXMLToken(sValue, XML_TRUE);
+                bProtected = IsXMLToken( it.toString(), XML_TRUE );
             else if ( nLocalToken == XML_PROTECTION_KEY )
-                sPassword = sValue;
+                sPassword = it.toString();
             else if (  nLocalToken == XML_PROTECTION_KEY_DIGEST_ALGORITHM )
-                meHash1 = ScPassHashHelper::getHashTypeFromURI( sValue );
+                meHash1 = ScPassHashHelper::getHashTypeFromURI( it.toString() );
             else if (  nLocalToken == XML_PROTECTION_KEY_DIGEST_ALGORITHM_2 )
-                meHash2 = ScPassHashHelper::getHashTypeFromURI( sValue );
+                meHash2 = ScPassHashHelper::getHashTypeFromURI( it.toString() );
         }
         else if ( nToken == ( NAMESPACE_TOKEN( XML_NAMESPACE_LO_EXT ) |
                                         XML_PROTECTION_KEY_DIGEST_ALGORITHM_2 ) )
         {
-            meHash2 = ScPassHashHelper::getHashTypeFromURI( sValue );
+            meHash2 = ScPassHashHelper::getHashTypeFromURI( it.toString() );
         }
     }
 }
diff --git a/sc/source/filter/xml/xmlcelli.cxx b/sc/source/filter/xml/xmlcelli.cxx
index 0f6292c..70b5b74 100644
--- a/sc/source/filter/xml/xmlcelli.cxx
+++ b/sc/source/filter/xml/xmlcelli.cxx
@@ -165,60 +165,57 @@ ScXMLTableRowCellContext::ScXMLTableRowCellContext( ScXMLImport& rImport,
         assert( dynamic_cast< sax_fastparser::FastAttributeList *>( xAttrList.get() ) != nullptr );
         pAttribList = static_cast< sax_fastparser::FastAttributeList *>( xAttrList.get() );
 
-        const std::vector< sal_Int32 >& rAttrList = pAttribList->getFastAttributeTokens();
-        for ( size_t i = 0; i < rAttrList.size(); i++ )
+        for ( auto it = pAttribList->begin(); it != pAttribList->end(); ++it)
         {
-            sal_uInt16 nToken = rTokenMap.Get( rAttrList[ i ] );
-            const OUString sValue = OUString(pAttribList->getFastAttributeValue(i),
-                                    pAttribList->AttributeValueLength(i), RTL_TEXTENCODING_UTF8);
+            sal_uInt16 nToken = rTokenMap.Get( it.getToken() );
             switch ( nToken )
             {
                 case XML_TOK_TABLE_ROW_CELL_ATTR_STYLE_NAME:
-                    xStyleName.reset(new OUString(sValue));
+                    xStyleName.reset( new OUString( it.toString() ) );
                     mbHasStyle = true;
                 break;
                 case XML_TOK_TABLE_ROW_CELL_ATTR_CONTENT_VALIDATION_NAME:
                     OSL_ENSURE(!maContentValidationName, "here should be only one Validation Name");
-                    if (!sValue.isEmpty())
-                        maContentValidationName.reset(sValue);
+                    if (!it.isEmpty())
+                        maContentValidationName.reset(it.toString());
                 break;
                 case XML_TOK_TABLE_ROW_CELL_ATTR_SPANNED_ROWS:
                     bIsMerged = true;
-                    nMergedRows = static_cast<SCROW>(sValue.toInt32());
+                    nMergedRows = static_cast<SCROW>(it.toInt32());
                 break;
                 case XML_TOK_TABLE_ROW_CELL_ATTR_SPANNED_COLS:
                     bIsMerged = true;
-                    nMergedCols = static_cast<SCCOL>(sValue.toInt32());
+                    nMergedCols = static_cast<SCCOL>(it.toInt32());
                 break;
                 case XML_TOK_TABLE_ROW_CELL_ATTR_SPANNED_MATRIX_COLS:
                     bIsMatrix = true;
-                    nMatrixCols = static_cast<SCCOL>(sValue.toInt32());
+                    nMatrixCols = static_cast<SCCOL>(it.toInt32());
                 break;
                 case XML_TOK_TABLE_ROW_CELL_ATTR_SPANNED_MATRIX_ROWS:
                     bIsMatrix = true;
-                    nMatrixRows = static_cast<SCROW>(sValue.toInt32());
+                    nMatrixRows = static_cast<SCROW>(it.toInt32());
                 break;
                 case XML_TOK_TABLE_ROW_CELL_ATTR_REPEATED:
                     nColsRepeated = static_cast<SCCOL>(std::min<sal_Int32>( MAXCOLCOUNT,
-                                std::max( sValue.toInt32(), static_cast<sal_Int32>(1) ) ));
+                                std::max( it.toInt32(), static_cast<sal_Int32>(1) ) ));
                 break;
                 case XML_TOK_TABLE_ROW_CELL_ATTR_VALUE_TYPE:
-                    nCellType = GetScImport().GetCellType(sValue);
+                    nCellType = GetScImport().GetCellType(it.toString());
                     bIsEmpty = false;
                 break;
                 case XML_TOK_TABLE_ROW_CELL_ATTR_NEW_VALUE_TYPE:
-                    if(sValue == "error")
+                    if(it.isString( "error" ) )
                         mbErrorValue = true;
                     else
-                        nCellType = GetScImport().GetCellType(sValue);
+                        nCellType = GetScImport().GetCellType(it.toString());
                     bIsEmpty = false;
                     mbNewValueType = true;
                 break;
                 case XML_TOK_TABLE_ROW_CELL_ATTR_VALUE:
                 {
-                    if (!sValue.isEmpty())
+                    if (!it.isEmpty())
                     {
-                        ::sax::Converter::convertDouble(fValue, sValue);
+                        ::sax::Converter::convertDouble(fValue, it.toString());
                         bIsEmpty = false;
 
                         //if office:value="0", let's get the text:p in case this is
@@ -231,36 +228,37 @@ ScXMLTableRowCellContext::ScXMLTableRowCellContext( ScXMLImport& rImport,
                 break;
                 case XML_TOK_TABLE_ROW_CELL_ATTR_DATE_VALUE:
                 {
-                    if (!sValue.isEmpty() && rXMLImport.SetNullDateOnUnitConverter())
+                    if (!it.isEmpty() && rXMLImport.SetNullDateOnUnitConverter())
                     {
-                        rXMLImport.GetMM100UnitConverter().convertDateTime(fValue, sValue);
+                        rXMLImport.GetMM100UnitConverter().convertDateTime(fValue, it.toString());
                         bIsEmpty = false;
                     }
                 }
                 break;
                 case XML_TOK_TABLE_ROW_CELL_ATTR_TIME_VALUE:
                 {
-                    if (!sValue.isEmpty())
+                    if (!it.isEmpty())
                     {
-                        ::sax::Converter::convertDuration(fValue, sValue);
+                        ::sax::Converter::convertDuration(fValue, it.toString());
                         bIsEmpty = false;
                     }
                 }
                 break;
                 case XML_TOK_TABLE_ROW_CELL_ATTR_STRING_VALUE:
                 {
-                    if (!sValue.isEmpty())
+                    if (!it.isEmpty())
                     {
                         OSL_ENSURE(!maStringValue, "here should be only one string value");
-                        maStringValue.reset(sValue);
+                        maStringValue.reset(it.toString());
                         bIsEmpty = false;
                     }
                 }
                 break;
                 case XML_TOK_TABLE_ROW_CELL_ATTR_BOOLEAN_VALUE:
                 {
-                    if (!sValue.isEmpty())
+                    if (!it.isEmpty())
                     {
+                        const OUString sValue = it.toString();
                         if ( IsXMLToken(sValue, XML_TRUE) )
                             fValue = 1.0;
                         else if ( IsXMLToken(sValue, XML_FALSE) )
@@ -273,17 +271,17 @@ ScXMLTableRowCellContext::ScXMLTableRowCellContext( ScXMLImport& rImport,
                 break;
                 case XML_TOK_TABLE_ROW_CELL_ATTR_FORMULA:
                 {
-                    if (!sValue.isEmpty())
+                    if (!it.isEmpty())
                     {
                         OSL_ENSURE(!maFormula, "here should be only one formula");
                         OUString aFormula, aFormulaNmsp;
-                        rXMLImport.ExtractFormulaNamespaceGrammar( aFormula, aFormulaNmsp, eGrammar, sValue );
+                        rXMLImport.ExtractFormulaNamespaceGrammar( aFormula, aFormulaNmsp, eGrammar, it.toString() );
                         maFormula.reset( FormulaWithNamespace(aFormula, aFormulaNmsp) );
                     }
                 }
                 break;
                 case XML_TOK_TABLE_ROW_CELL_ATTR_CURRENCY:
-                    xCurrencySymbol.reset(new OUString(sValue));
+                    xCurrencySymbol.reset( new OUString( it.toString() ) );
                 break;
                 default:
                     ;
diff --git a/sc/source/filter/xml/xmlrowi.cxx b/sc/source/filter/xml/xmlrowi.cxx
index a840958..0be4934 100644
--- a/sc/source/filter/xml/xmlrowi.cxx
+++ b/sc/source/filter/xml/xmlrowi.cxx
@@ -59,37 +59,34 @@ ScXMLTableRowContext::ScXMLTableRowContext( ScXMLImport& rImport,
         assert( dynamic_cast< sax_fastparser::FastAttributeList *>( xAttrList.get() ) != nullptr );
         pAttribList = static_cast< sax_fastparser::FastAttributeList *>( xAttrList.get() );
 
-        const std::vector< sal_Int32 >& rAttrList = pAttribList->getFastAttributeTokens();
-        for ( size_t i = 0; i < rAttrList.size(); i++ )
+        for ( auto it = pAttribList->begin(); it != pAttribList->end(); ++it)
         {
-            const OUString sValue = OUString(pAttribList->getFastAttributeValue(i),
-                                    pAttribList->AttributeValueLength(i), RTL_TEXTENCODING_UTF8);
-            switch( rAttrTokenMap.Get( rAttrList[ i ] ) )
+            switch( rAttrTokenMap.Get( it.getToken() ) )
             {
                 case XML_TOK_TABLE_ROW_ATTR_STYLE_NAME:
                 {
-                    sStyleName = sValue;
+                    sStyleName = it.toString();
                 }
                 break;
                 case XML_TOK_TABLE_ROW_ATTR_VISIBILITY:
                 {
-                    sVisibility = sValue;
+                    sVisibility = it.toString();
                 }
                 break;
                 case XML_TOK_TABLE_ROW_ATTR_REPEATED:
                 {
-                    nRepeatedRows = std::max( sValue.toInt32(), (sal_Int32) 1 );
+                    nRepeatedRows = std::max( it.toInt32(), (sal_Int32) 1 );
                     nRepeatedRows = std::min( nRepeatedRows, MAXROWCOUNT );
                 }
                 break;
                 case XML_TOK_TABLE_ROW_ATTR_DEFAULT_CELL_STYLE_NAME:
                 {
-                    sCellStyleName = sValue;
+                    sCellStyleName = it.toString();
                 }
                 break;
                 /*case XML_TOK_TABLE_ROW_ATTR_USE_OPTIMAL_HEIGHT:
                 {
-                    sOptimalHeight = sValue;
+                    sOptimalHeight = it.toString();
                 }
                 break;*/
             }
diff --git a/sc/source/filter/xml/xmltabi.cxx b/sc/source/filter/xml/xmltabi.cxx
index f482b13..065ee00 100644
--- a/sc/source/filter/xml/xmltabi.cxx
+++ b/sc/source/filter/xml/xmltabi.cxx
@@ -151,37 +151,34 @@ ScXMLTableContext::ScXMLTableContext( ScXMLImport& rImport,
         pAttribList = static_cast< sax_fastparser::FastAttributeList *>( xAttrList.get() );
 
         const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetTableAttrTokenMap();
-        const std::vector< sal_Int32 >& rAttrList = pAttribList->getFastAttributeTokens();
-        for ( size_t i = 0; i < rAttrList.size(); i++ )
+        for ( auto it = pAttribList->begin(); it != pAttribList->end(); ++it)
         {
-            const OUString sValue = OUString(pAttribList->getFastAttributeValue(i),
-                                    pAttribList->AttributeValueLength(i), RTL_TEXTENCODING_UTF8);
-            switch( rAttrTokenMap.Get( rAttrList[ i ] ) )
+            switch( rAttrTokenMap.Get( it.getToken() ) )
             {
                 case XML_TOK_TABLE_NAME:
-                        sName = sValue;
+                        sName = it.toString();
                     break;
                 case XML_TOK_TABLE_STYLE_NAME:
-                        sStyleName = sValue;
+                        sStyleName = it.toString();
                     break;
                 case XML_TOK_TABLE_PROTECTED:
-                    aProtectData.mbProtected = IsXMLToken(sValue, XML_TRUE);
+                    aProtectData.mbProtected = IsXMLToken( it.toString(), XML_TRUE );
                 break;
                 case XML_TOK_TABLE_PRINT_RANGES:
-                        sPrintRanges = sValue;
+                        sPrintRanges = it.toString();
                     break;
                 case XML_TOK_TABLE_PASSWORD:
-                    aProtectData.maPassword = sValue;
+                    aProtectData.maPassword = it.toString();
                 break;
                 case XML_TOK_TABLE_PASSHASH:
-                    aProtectData.meHash1 = ScPassHashHelper::getHashTypeFromURI( sValue );
+                    aProtectData.meHash1 = ScPassHashHelper::getHashTypeFromURI( it.toString() );
                 break;
                 case XML_TOK_TABLE_PASSHASH_2:
-                    aProtectData.meHash2 = ScPassHashHelper::getHashTypeFromURI( sValue );
+                    aProtectData.meHash2 = ScPassHashHelper::getHashTypeFromURI( it.toString() );
                 break;
                 case XML_TOK_TABLE_PRINT:
                     {
-                        if (IsXMLToken(sValue, XML_FALSE))
+                        if (IsXMLToken( it.toString(), XML_FALSE) )
                             bPrintEntireSheet = false;
                     }
                     break;


More information about the Libreoffice-commits mailing list