Kaydet (Commit) b5bd7e60 authored tarafından Matteo Casalin's avatar Matteo Casalin

Reserve vector capacity in advance + minor optimizations

Change-Id: I04eea6825c02ea0c076b525e58a1dc86dd290b64
üst 0bb1d92c
...@@ -90,6 +90,10 @@ namespace { ...@@ -90,6 +90,10 @@ namespace {
const std::set<sal_uInt16> &rUsedNums, const std::set<sal_uInt16> &rUsedNums,
size_t numRequired) size_t numRequired)
{ {
if (!numRequired)
return;
rLowestUnusedNums.reserve(numRequired);
sal_uInt16 newNum = 0; sal_uInt16 newNum = 0;
std::set<sal_uInt16>::iterator it; std::set<sal_uInt16>::iterator it;
//Start by using numbers from gaps in rUsedNums //Start by using numbers from gaps in rUsedNums
...@@ -98,16 +102,17 @@ namespace { ...@@ -98,16 +102,17 @@ namespace {
while ( newNum < *it ) while ( newNum < *it )
{ {
rLowestUnusedNums.push_back( newNum++ ); rLowestUnusedNums.push_back( newNum++ );
if ( rLowestUnusedNums.size() >= numRequired ) if ( --numRequired == 0)
return; return;
} }
newNum++; newNum++;
} }
//Filled in all gaps. Fill the rest of the list with new numbers. //Filled in all gaps. Fill the rest of the list with new numbers.
while ( rLowestUnusedNums.size() < numRequired ) do
{ {
rLowestUnusedNums.push_back( newNum++ ); rLowestUnusedNums.push_back( newNum++ );
} }
while ( --numRequired > 0 );
} }
} }
......
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