Commit 5ab2ccae by Maarten L. Hekkelman

avoid calling cif::Category::size() too often

parent 1017d086
...@@ -2152,6 +2152,7 @@ class Category ...@@ -2152,6 +2152,7 @@ class Category
std::vector<ItemColumn> mColumns; std::vector<ItemColumn> mColumns;
ItemRow *mHead; ItemRow *mHead;
ItemRow *mTail; ItemRow *mTail;
size_t mLastUniqueNr = 0;
class CatIndex *mIndex; class CatIndex *mIndex;
std::vector<Linked> mParentLinks, mChildLinks; std::vector<Linked> mParentLinks, mChildLinks;
......
...@@ -1601,11 +1601,13 @@ std::string Category::getUniqueID(std::function<std::string(int)> generator) ...@@ -1601,11 +1601,13 @@ std::string Category::getUniqueID(std::function<std::string(int)> generator)
if (mCatValidator != nullptr and mCatValidator->mKeys.size() == 1) if (mCatValidator != nullptr and mCatValidator->mKeys.size() == 1)
key = mCatValidator->mKeys.front(); key = mCatValidator->mKeys.front();
size_t nr = size(); // calling size() often is a waste of resources
if (mLastUniqueNr == 0)
mLastUniqueNr = size();
for (;;) for (;;)
{ {
std::string result = generator(int(nr++)); std::string result = generator(static_cast<int>(mLastUniqueNr++));
if (exists(Key(key) == result)) if (exists(Key(key) == result))
continue; continue;
......
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