Kaydet (Commit) 28ff54f9 authored tarafından Caolán McNamara's avatar Caolán McNamara

ofz optimize this unique name generator a tad

Change-Id: Ie18f71febbfc5e1ed4300782919bbd92d76ea51b
Reviewed-on: https://gerrit.libreoffice.org/48318Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarCaolán McNamara <caolanm@redhat.com>
Tested-by: 's avatarCaolán McNamara <caolanm@redhat.com>
üst c3272ca4
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment