[Libreoffice-commits] core.git: filter/source include/filter writerfilter/source

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Sat Aug 28 14:10:38 UTC 2021


 filter/source/msfilter/util.cxx                  |   47 ++++++++++++++++-------
 include/filter/msfilter/util.hxx                 |    1 
 writerfilter/source/dmapper/BorderHandler.cxx    |    2 
 writerfilter/source/dmapper/CellColorHandler.cxx |    6 +-
 writerfilter/source/dmapper/DomainMapper.cxx     |    2 
 writerfilter/source/dmapper/TDefTableHandler.cxx |    2 
 writerfilter/source/rtftok/rtfsdrimport.cxx      |   14 +++---
 7 files changed, 47 insertions(+), 27 deletions(-)

New commits:
commit 30bd841e2d8f47e49711d928d600573339708b03
Author:     Noel Grandin <noelgrandin at gmail.com>
AuthorDate: Fri Aug 27 20:50:59 2021 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Sat Aug 28 16:10:04 2021 +0200

    avoid unnecessary OString to OUString conversion
    
    speeds up loading some writer files
    
    Change-Id: Ia6dddf3a9e8990b8cd3f600c86c758573c7ea2ec
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121183
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/filter/source/msfilter/util.cxx b/filter/source/msfilter/util.cxx
index 148f165d3fb1..23b4de1e87be 100644
--- a/filter/source/msfilter/util.cxx
+++ b/filter/source/msfilter/util.cxx
@@ -125,23 +125,42 @@ sal_Unicode bestFitOpenSymbolToMSFont(sal_Unicode cChar,
 
 OString ConvertColor( const Color &rColor )
 {
-    OString color( "auto" );
+    static constexpr OStringLiteral AUTO( "auto" );
 
-    if ( rColor != COL_AUTO )
-    {
-        const char pHexDigits[] = "0123456789ABCDEF";
-        char pBuffer[] = "000000";
+    if ( rColor == COL_AUTO )
+        return AUTO;
 
-        pBuffer[0] = pHexDigits[ ( rColor.GetRed()   >> 4 ) & 0x0F ];
-        pBuffer[1] = pHexDigits[   rColor.GetRed()          & 0x0F ];
-        pBuffer[2] = pHexDigits[ ( rColor.GetGreen() >> 4 ) & 0x0F ];
-        pBuffer[3] = pHexDigits[   rColor.GetGreen()        & 0x0F ];
-        pBuffer[4] = pHexDigits[ ( rColor.GetBlue()  >> 4 ) & 0x0F ];
-        pBuffer[5] = pHexDigits[   rColor.GetBlue()         & 0x0F ];
+    const char pHexDigits[] = "0123456789ABCDEF";
+    char pBuffer[] = "000000";
 
-        color = OString( pBuffer );
-    }
-    return color;
+    pBuffer[0] = pHexDigits[ ( rColor.GetRed()   >> 4 ) & 0x0F ];
+    pBuffer[1] = pHexDigits[   rColor.GetRed()          & 0x0F ];
+    pBuffer[2] = pHexDigits[ ( rColor.GetGreen() >> 4 ) & 0x0F ];
+    pBuffer[3] = pHexDigits[   rColor.GetGreen()        & 0x0F ];
+    pBuffer[4] = pHexDigits[ ( rColor.GetBlue()  >> 4 ) & 0x0F ];
+    pBuffer[5] = pHexDigits[   rColor.GetBlue()         & 0x0F ];
+
+    return OString( pBuffer );
+}
+
+OUString ConvertColorOU( const Color &rColor )
+{
+    static constexpr OUStringLiteral AUTO( u"auto" );
+
+    if ( rColor == COL_AUTO )
+        return AUTO;
+
+    const char pHexDigits[] = "0123456789ABCDEF";
+    sal_Unicode pBuffer[] = u"000000";
+
+    pBuffer[0] = pHexDigits[ ( rColor.GetRed()   >> 4 ) & 0x0F ];
+    pBuffer[1] = pHexDigits[   rColor.GetRed()          & 0x0F ];
+    pBuffer[2] = pHexDigits[ ( rColor.GetGreen() >> 4 ) & 0x0F ];
+    pBuffer[3] = pHexDigits[   rColor.GetGreen()        & 0x0F ];
+    pBuffer[4] = pHexDigits[ ( rColor.GetBlue()  >> 4 ) & 0x0F ];
+    pBuffer[5] = pHexDigits[   rColor.GetBlue()         & 0x0F ];
+
+    return OUString( pBuffer );
 }
 
 #define IN2MM100( v )    static_cast< sal_Int32 >( (v) * 2540.0 + 0.5 )
diff --git a/include/filter/msfilter/util.hxx b/include/filter/msfilter/util.hxx
index 7e25e701420d..f2c2a0dbfcfe 100644
--- a/include/filter/msfilter/util.hxx
+++ b/include/filter/msfilter/util.hxx
@@ -62,6 +62,7 @@ MSFILTER_DLLPUBLIC sal_Unicode bestFitOpenSymbolToMSFont(sal_Unicode cBullet,
  * @param rColor color to convert
  */
 MSFILTER_DLLPUBLIC OString ConvertColor( const Color &rColor );
+MSFILTER_DLLPUBLIC OUString ConvertColorOU( const Color &rColor );
 
 
 /** Paper size in 1/100 millimeters. */
diff --git a/writerfilter/source/dmapper/BorderHandler.cxx b/writerfilter/source/dmapper/BorderHandler.cxx
index 0045805d6e85..c9c793ca35ff 100644
--- a/writerfilter/source/dmapper/BorderHandler.cxx
+++ b/writerfilter/source/dmapper/BorderHandler.cxx
@@ -66,7 +66,7 @@ void BorderHandler::lcl_attribute(Id rName, Value & rVal)
         break;
         case NS_ooxml::LN_CT_Border_color:
             m_nLineColor = nIntValue;
-            appendGrabBag("color", OUString::fromUtf8(msfilter::util::ConvertColor(Color(ColorTransparency, nIntValue))));
+            appendGrabBag("color", msfilter::util::ConvertColorOU(Color(ColorTransparency, nIntValue)));
         break;
         case NS_ooxml::LN_CT_Border_space: // border distance in points
             m_nLineDistance = ConversionHelper::convertTwipToMM100( nIntValue * 20 );
diff --git a/writerfilter/source/dmapper/CellColorHandler.cxx b/writerfilter/source/dmapper/CellColorHandler.cxx
index 193477a31fc2..765d5a3a5273 100644
--- a/writerfilter/source/dmapper/CellColorHandler.cxx
+++ b/writerfilter/source/dmapper/CellColorHandler.cxx
@@ -107,7 +107,7 @@ void CellColorHandler::lcl_attribute(Id rName, Value & rVal)
         }
         break;
         case NS_ooxml::LN_CT_Shd_fill:
-            createGrabBag("fill", uno::makeAny(OUString::fromUtf8(msfilter::util::ConvertColor(Color(ColorTransparency, nIntValue)))));
+            createGrabBag("fill", uno::makeAny(msfilter::util::ConvertColorOU(Color(ColorTransparency, nIntValue))));
             if( nIntValue == sal_Int32(COL_AUTO) )
                 nIntValue = 0xffffff; //fill color auto means white
             else
@@ -117,7 +117,7 @@ void CellColorHandler::lcl_attribute(Id rName, Value & rVal)
             m_bFillSpecified = true;
         break;
         case NS_ooxml::LN_CT_Shd_color:
-            createGrabBag("color", uno::makeAny(OUString::fromUtf8(msfilter::util::ConvertColor(Color(ColorTransparency, nIntValue)))));
+            createGrabBag("color", uno::makeAny(msfilter::util::ConvertColorOU(Color(ColorTransparency, nIntValue))));
             if( nIntValue == sal_Int32(COL_AUTO) )
                 nIntValue = 0; //shading color auto means black
             //color of the shading
@@ -286,7 +286,7 @@ TablePropertyMapPtr  CellColorHandler::getProperties()
         pPropertyMap->Insert( m_OutputFormat == Form ? PROP_BACK_COLOR
                             : PROP_CHAR_BACK_COLOR, uno::makeAny( nApplyColor ));
 
-    createGrabBag("originalColor", uno::makeAny(OUString::fromUtf8(msfilter::util::ConvertColor(Color(ColorTransparency, nApplyColor)))));
+    createGrabBag("originalColor", uno::makeAny(msfilter::util::ConvertColorOU(Color(ColorTransparency, nApplyColor))));
 
     return pPropertyMap;
 }
diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx
index 9503306b05ec..c994d7b6df0b 100644
--- a/writerfilter/source/dmapper/DomainMapper.cxx
+++ b/writerfilter/source/dmapper/DomainMapper.cxx
@@ -334,7 +334,7 @@ void DomainMapper::lcl_attribute(Id nName, Value & val)
         case NS_ooxml::LN_CT_Color_val:
             if (m_pImpl->GetTopContext())
                 m_pImpl->GetTopContext()->Insert(PROP_CHAR_COLOR, uno::makeAny( nIntValue ) );
-            m_pImpl->appendGrabBag(m_pImpl->m_aSubInteropGrabBag, "val", OUString::fromUtf8(msfilter::util::ConvertColor(Color(ColorTransparency,nIntValue))));
+            m_pImpl->appendGrabBag(m_pImpl->m_aSubInteropGrabBag, "val", msfilter::util::ConvertColorOU(Color(ColorTransparency,nIntValue)));
             break;
         case NS_ooxml::LN_CT_Underline_color:
             if (m_pImpl->GetTopContext())
diff --git a/writerfilter/source/dmapper/TDefTableHandler.cxx b/writerfilter/source/dmapper/TDefTableHandler.cxx
index 9d7059feece6..53e10529274f 100644
--- a/writerfilter/source/dmapper/TDefTableHandler.cxx
+++ b/writerfilter/source/dmapper/TDefTableHandler.cxx
@@ -284,7 +284,7 @@ void TDefTableHandler::lcl_attribute(Id rName, Value & rVal)
             appendGrabBag("val", TDefTableHandler::getBorderTypeString(nIntValue));
         break;
         case NS_ooxml::LN_CT_Border_color:
-            appendGrabBag("color", OUString::fromUtf8(msfilter::util::ConvertColor(Color(ColorTransparency,nIntValue))));
+            appendGrabBag("color", msfilter::util::ConvertColorOU(Color(ColorTransparency,nIntValue)));
             m_nLineColor = nIntValue;
         break;
         case NS_ooxml::LN_CT_Border_space:
diff --git a/writerfilter/source/rtftok/rtfsdrimport.cxx b/writerfilter/source/rtftok/rtfsdrimport.cxx
index 20e9bbdce6b8..9a1c9b4d4302 100644
--- a/writerfilter/source/rtftok/rtfsdrimport.cxx
+++ b/writerfilter/source/rtftok/rtfsdrimport.cxx
@@ -441,15 +441,15 @@ void RTFSdrImport::resolve(RTFShape& rShape, bool bClose, ShapeOrPict const shap
                 xPropertySet->setPropertyValue("FillColor", aAny);
 
             // fillType will decide, possible it'll be the start color of a gradient.
-            aFillModel.moColor.set("#"
-                                   + OUString::fromUtf8(msfilter::util::ConvertColor(
-                                         Color(ColorTransparency, aAny.get<sal_Int32>()))));
+            aFillModel.moColor.set(
+                "#"
+                + msfilter::util::ConvertColorOU(Color(ColorTransparency, aAny.get<sal_Int32>())));
         }
         else if (rProperty.first == "fillBackColor")
             // fillType will decide, possible it'll be the end color of a gradient.
             aFillModel.moColor2.set("#"
-                                    + OUString::fromUtf8(msfilter::util::ConvertColor(
-                                          msfilter::util::BGRToRGB(rProperty.second.toInt32()))));
+                                    + msfilter::util::ConvertColorOU(
+                                          msfilter::util::BGRToRGB(rProperty.second.toInt32())));
         else if (rProperty.first == "lineColor")
             aLineColor <<= msfilter::util::BGRToRGB(rProperty.second.toInt32());
         else if (rProperty.first == "lineBackColor")
@@ -671,8 +671,8 @@ void RTFSdrImport::resolve(RTFShape& rShape, bool bClose, ShapeOrPict const shap
         }
         else if (rProperty.first == "shadowColor")
             aShadowModel.moColor.set("#"
-                                     + OUString::fromUtf8(msfilter::util::ConvertColor(
-                                           msfilter::util::BGRToRGB(rProperty.second.toInt32()))));
+                                     + msfilter::util::ConvertColorOU(
+                                           msfilter::util::BGRToRGB(rProperty.second.toInt32())));
         else if (rProperty.first == "shadowOffsetX")
             // EMUs to points
             aShadowModel.moOffset.set(OUString::number(rProperty.second.toDouble() / 12700) + "pt");


More information about the Libreoffice-commits mailing list