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

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Fri Aug 17 06:23:25 UTC 2018


 sc/source/filter/xml/XMLStylesExportHelper.cxx |   24 +++++-------------------
 sc/source/filter/xml/XMLStylesExportHelper.hxx |    6 +++---
 sc/source/filter/xml/xmlexprt.cxx              |   16 ++++++----------
 3 files changed, 14 insertions(+), 32 deletions(-)

New commits:
commit 1b95eb30f6358a9ebdedee2888be8273120669c8
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Thu Aug 16 11:03:36 2018 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Fri Aug 17 08:22:51 2018 +0200

    loplugin:useuniqueptr in ScColumnRowStylesBase
    
    Change-Id: I44e9cb38f57684930a94bd1f185e87a9605b65c2
    Reviewed-on: https://gerrit.libreoffice.org/59225
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/sc/source/filter/xml/XMLStylesExportHelper.cxx b/sc/source/filter/xml/XMLStylesExportHelper.cxx
index 57accced6e18..dba0fee848f6 100644
--- a/sc/source/filter/xml/XMLStylesExportHelper.cxx
+++ b/sc/source/filter/xml/XMLStylesExportHelper.cxx
@@ -982,18 +982,11 @@ ScColumnRowStylesBase::ScColumnRowStylesBase()
 
 ScColumnRowStylesBase::~ScColumnRowStylesBase()
 {
-    auto i(aStyleNames.begin());
-    auto endi(aStyleNames.end());
-    while (i != endi)
-    {
-        delete *i;
-        ++i;
-    }
 }
 
-sal_Int32 ScColumnRowStylesBase::AddStyleName(OUString* pString)
+sal_Int32 ScColumnRowStylesBase::AddStyleName(const OUString & rString)
 {
-    aStyleNames.push_back(pString);
+    aStyleNames.push_back(rString);
     return aStyleNames.size() - 1;
 }
 
@@ -1002,7 +995,7 @@ sal_Int32 ScColumnRowStylesBase::GetIndexOfStyleName(const OUString& rString, co
     sal_Int32 nPrefixLength(rPrefix.getLength());
     OUString sTemp(rString.copy(nPrefixLength));
     sal_Int32 nIndex(sTemp.toInt32());
-    if (nIndex > 0 && static_cast<size_t>(nIndex-1) < aStyleNames.size() && *aStyleNames.at(nIndex - 1) == rString)
+    if (nIndex > 0 && static_cast<size_t>(nIndex-1) < aStyleNames.size() && aStyleNames.at(nIndex - 1) == rString)
         return nIndex - 1;
     else
     {
@@ -1010,7 +1003,7 @@ sal_Int32 ScColumnRowStylesBase::GetIndexOfStyleName(const OUString& rString, co
         bool bFound(false);
         while (!bFound && static_cast<size_t>(i) < aStyleNames.size())
         {
-            if (*aStyleNames.at(i) == rString)
+            if (aStyleNames.at(i) == rString)
                 bFound = true;
             else
                 ++i;
@@ -1022,15 +1015,8 @@ sal_Int32 ScColumnRowStylesBase::GetIndexOfStyleName(const OUString& rString, co
     }
 }
 
-OUString* ScColumnRowStylesBase::GetStyleNameByIndex(const sal_Int32 nIndex)
+OUString& ScColumnRowStylesBase::GetStyleNameByIndex(const sal_Int32 nIndex)
 {
-    if ( nIndex < 0 || nIndex >= sal::static_int_cast<sal_Int32>( aStyleNames.size() ) )
-    {
-        // should no longer happen, use first style then
-        OSL_FAIL("GetStyleNameByIndex: invalid index");
-        return aStyleNames[0];
-    }
-
     return aStyleNames[nIndex];
 }
 
diff --git a/sc/source/filter/xml/XMLStylesExportHelper.hxx b/sc/source/filter/xml/XMLStylesExportHelper.hxx
index 6012a5b7e324..478e94d75f7f 100644
--- a/sc/source/filter/xml/XMLStylesExportHelper.hxx
+++ b/sc/source/filter/xml/XMLStylesExportHelper.hxx
@@ -205,16 +205,16 @@ public:
 
 class ScColumnRowStylesBase
 {
-    std::vector<OUString*>   aStyleNames;
+    std::vector<OUString>   aStyleNames;
 
 public:
     ScColumnRowStylesBase();
     virtual ~ScColumnRowStylesBase();
 
     virtual void AddNewTable(const sal_Int32 nTable, const sal_Int32 nFields) = 0;
-    sal_Int32 AddStyleName(OUString* pString);
+    sal_Int32 AddStyleName(const OUString & rString);
     sal_Int32 GetIndexOfStyleName(const OUString& rString, const OUString& rPrefix);
-    OUString* GetStyleNameByIndex(const sal_Int32 nIndex);
+    OUString& GetStyleNameByIndex(const sal_Int32 nIndex);
 };
 
 struct ScColumnStyle
diff --git a/sc/source/filter/xml/xmlexprt.cxx b/sc/source/filter/xml/xmlexprt.cxx
index 9312936fd3d5..9fffd6a4c637 100644
--- a/sc/source/filter/xml/xmlexprt.cxx
+++ b/sc/source/filter/xml/xmlexprt.cxx
@@ -747,7 +747,7 @@ void ScXMLExport::WriteSingleColumn(const sal_Int32 nRepeatColumns, const sal_In
     const sal_Int32 nIndex, const bool bIsAutoStyle, const bool bIsVisible)
 {
     CheckAttrList();
-    AddAttribute(sAttrStyleName, *pColumnStyles->GetStyleNameByIndex(nStyleIndex));
+    AddAttribute(sAttrStyleName, pColumnStyles->GetStyleNameByIndex(nStyleIndex));
     if (!bIsVisible)
         AddAttribute(XML_NAMESPACE_TABLE, XML_VISIBILITY, XML_COLLAPSE);
     if (nRepeatColumns > 1)
@@ -1365,7 +1365,7 @@ void ScXMLExport::WriteRowStartTag(
     const sal_Int32 nIndex, const sal_Int32 nEqualRows,
     bool bHidden, bool bFiltered)
 {
-    AddAttribute(sAttrStyleName, *pRowStyles->GetStyleNameByIndex(nIndex));
+    AddAttribute(sAttrStyleName, pRowStyles->GetStyleNameByIndex(nIndex));
     if (bHidden)
     {
         if (bFiltered)
@@ -2202,8 +2202,7 @@ void ScXMLExport::AddStyleFromColumn(const uno::Reference<beans::XPropertySet>&
             {
                 GetAutoStylePool()->RegisterName(XML_STYLE_FAMILY_TABLE_COLUMN, *pOldName);
                 // add to pColumnStyles, so the name is found for normal sheets
-                OUString* pTemp(new OUString(*pOldName));
-                rIndex = pColumnStyles->AddStyleName(pTemp);
+                rIndex = pColumnStyles->AddStyleName(*pOldName);
             }
         }
         else
@@ -2211,8 +2210,7 @@ void ScXMLExport::AddStyleFromColumn(const uno::Reference<beans::XPropertySet>&
             OUString sName;
             if (GetAutoStylePool()->Add(sName, XML_STYLE_FAMILY_TABLE_COLUMN, sParent, aPropStates))
             {
-                OUString* pTemp(new OUString(sName));
-                rIndex = pColumnStyles->AddStyleName(pTemp);
+                rIndex = pColumnStyles->AddStyleName(sName);
             }
             else
                 rIndex = pColumnStyles->GetIndexOfStyleName(sName, XML_STYLE_FAMILY_TABLE_COLUMN_STYLES_PREFIX);
@@ -2233,8 +2231,7 @@ void ScXMLExport::AddStyleFromRow(const uno::Reference<beans::XPropertySet>& xRo
             {
                 GetAutoStylePool()->RegisterName(XML_STYLE_FAMILY_TABLE_ROW, *pOldName);
                 // add to pRowStyles, so the name is found for normal sheets
-                OUString* pTemp(new OUString(*pOldName));
-                rIndex = pRowStyles->AddStyleName(pTemp);
+                rIndex = pRowStyles->AddStyleName(*pOldName);
             }
         }
         else
@@ -2242,8 +2239,7 @@ void ScXMLExport::AddStyleFromRow(const uno::Reference<beans::XPropertySet>& xRo
             OUString sName;
             if (GetAutoStylePool()->Add(sName, XML_STYLE_FAMILY_TABLE_ROW, sParent, aPropStates))
             {
-                OUString* pTemp(new OUString(sName));
-                rIndex = pRowStyles->AddStyleName(pTemp);
+                rIndex = pRowStyles->AddStyleName(sName);
             }
             else
                 rIndex = pRowStyles->GetIndexOfStyleName(sName, XML_STYLE_FAMILY_TABLE_ROW_STYLES_PREFIX);


More information about the Libreoffice-commits mailing list