sd/source/ui/unoidl/unomodel.cxx | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-)
New commits: commit 28ff54f9bb0d3f96d7a6fd3cbf3fa590c9ef45d6 Author: Caolán McNamara <caol...@redhat.com> Date: Mon Jan 22 12:17:56 2018 +0000 ofz optimize this unique name generator a tad Change-Id: Ie18f71febbfc5e1ed4300782919bbd92d76ea51b Reviewed-on: https://gerrit.libreoffice.org/48318 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Caolán McNamara <caol...@redhat.com> Tested-by: Caolán McNamara <caol...@redhat.com> diff --git a/sd/source/ui/unoidl/unomodel.cxx b/sd/source/ui/unoidl/unomodel.cxx index 8e85f989b376..0c6d1fd7b877 100644 --- a/sd/source/ui/unoidl/unomodel.cxx +++ b/sd/source/ui/unoidl/unomodel.cxx @@ -3130,27 +3130,24 @@ uno::Reference< drawing::XDrawPage > SAL_CALL SdMasterPagesAccess::insertNewByIn OUString aPrefix( aStdPrefix ); bool bUnique = true; - sal_Int32 i = 0; - do - { - bUnique = true; - for( sal_Int32 nMaster = 1; nMaster < nMPageCount; nMaster++ ) - { - SdPage* pPage = static_cast<SdPage*>(pDoc->GetMasterPage(static_cast<sal_uInt16>(nMaster))); - if( pPage && pPage->GetName() == aPrefix ) - { - bUnique = false; - break; - } - } - if( !bUnique ) - { - i++; - aPrefix = aStdPrefix + " " + OUString::number( i ); - } + std::vector<OUString> aPageNames; + for (sal_Int32 nMaster = 1; nMaster < nMPageCount; ++nMaster) + { + const SdPage* pPage = static_cast<const SdPage*>(pDoc->GetMasterPage(static_cast<sal_uInt16>(nMaster))); + if (!pPage) + continue; + aPageNames.push_back(pPage->GetName()); + if (aPageNames.back() == aPrefix) + bUnique = false; + } - } while( !bUnique ); + sal_Int32 i = 0; + while (!bUnique) + { + aPrefix = aStdPrefix + " " + OUString::number(++i); + bUnique = std::find(aPageNames.begin(), aPageNames.end(), aPrefix) == aPageNames.end(); + } OUString aLayoutName( aPrefix ); aLayoutName += SD_LT_SEPARATOR; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits