summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2018-01-22 12:17:56 +0000
committerCaolán McNamara <caolanm@redhat.com>2018-01-22 21:42:58 +0100
commit28ff54f9bb0d3f96d7a6fd3cbf3fa590c9ef45d6 (patch)
tree4e82196882f89f9b3b11707a5c9355dc136bcd4f
parentc3272ca47439464eee5501605e7282ecd0d6313a (diff)
ofz optimize this unique name generator a tad
Change-Id: Ie18f71febbfc5e1ed4300782919bbd92d76ea51b Reviewed-on: https://gerrit.libreoffice.org/48318 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r--sd/source/ui/unoidl/unomodel.cxx35
1 files changed, 16 insertions, 19 deletions
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;