From 389dab874764823c7a4b7a0b8a257f001d83ec02 Mon Sep 17 00:00:00 2001 From: Hugo Parente Lima Date: Thu, 4 Aug 2011 18:46:37 -0300 Subject: Compute the type indexes if needed when calling getMaxTypeIndex(). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewer: Renato Araújo Marcelo Lira --- typedatabase.cpp | 76 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 41 insertions(+), 35 deletions(-) diff --git a/typedatabase.cpp b/typedatabase.cpp index 98ffc0b..4ff2128 100644 --- a/typedatabase.cpp +++ b/typedatabase.cpp @@ -441,51 +441,57 @@ static bool compareTypeEntriesByName(const TypeEntry* t1, const TypeEntry* t2) return t1->qualifiedCppName() < t2->qualifiedCppName(); } -int getTypeIndex(const TypeEntry* typeEntry) -{ - if (computeTypeIndexes) { - TypeDatabase* tdb = TypeDatabase::instance(); - typedef QMap > GroupedTypeEntries; - GroupedTypeEntries groupedEntries; - - // Group type entries by revision numbers - TypeEntryHash allEntries = tdb->allEntries(); - foreach (QList entryList, allEntries) { - foreach (TypeEntry* entry, entryList) { - if (entry->isPrimitive() - || entry->isContainer() - || entry->isFunction() - || !entry->generateCode() - || entry->isEnumValue() - || entry->isVarargs() - || entry->isTypeSystem() - || entry->isVoid() - || entry->isCustom()) - continue; - groupedEntries[getTypeRevision(entry)] << entry; - } +static void _computeTypeIndexes() +{ + TypeDatabase* tdb = TypeDatabase::instance(); + typedef QMap > GroupedTypeEntries; + GroupedTypeEntries groupedEntries; + + // Group type entries by revision numbers + TypeEntryHash allEntries = tdb->allEntries(); + foreach (QList entryList, allEntries) { + foreach (TypeEntry* entry, entryList) { + if (entry->isPrimitive() + || entry->isContainer() + || entry->isFunction() + || !entry->generateCode() + || entry->isEnumValue() + || entry->isVarargs() + || entry->isTypeSystem() + || entry->isVoid() + || entry->isCustom()) + continue; + groupedEntries[getTypeRevision(entry)] << entry; } + } - maxTypeIndex = 0; - GroupedTypeEntries::iterator it = groupedEntries.begin(); - for (; it != groupedEntries.end(); ++it) { - // Remove duplicates - QList::iterator newEnd = std::unique(it.value().begin(), it.value().end()); - it.value().erase(newEnd, it.value().end()); - // Sort the type entries by name - qSort(it.value().begin(), newEnd, compareTypeEntriesByName); - - foreach (TypeEntry* entry, it.value()) { - (*typeEntryFields())[entry].second = maxTypeIndex++; - } + maxTypeIndex = 0; + GroupedTypeEntries::iterator it = groupedEntries.begin(); + for (; it != groupedEntries.end(); ++it) { + // Remove duplicates + QList::iterator newEnd = std::unique(it.value().begin(), it.value().end()); + it.value().erase(newEnd, it.value().end()); + // Sort the type entries by name + qSort(it.value().begin(), newEnd, compareTypeEntriesByName); + + foreach (TypeEntry* entry, it.value()) { + (*typeEntryFields())[entry].second = maxTypeIndex++; } } + computeTypeIndexes = false; +} +int getTypeIndex(const TypeEntry* typeEntry) +{ + if (computeTypeIndexes) + _computeTypeIndexes(); return typeEntryFields()->value(typeEntry).second; } int getMaxTypeIndex() { + if (computeTypeIndexes) + _computeTypeIndexes(); return maxTypeIndex; } -- cgit v1.2.3