aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHugo Parente Lima <hugo.pl@gmail.com>2011-08-04 18:46:37 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2012-03-09 19:10:18 -0300
commit389dab874764823c7a4b7a0b8a257f001d83ec02 (patch)
tree6f1dc55ea9bdabbc32458ef11a902b0f46ad09a6
parent68976e42cd1d765baa73a85bc1b80da829996ec1 (diff)
Compute the type indexes if needed when calling getMaxTypeIndex().
Reviewer: Renato Ara├║jo <renato.filho@openbossa.org> Marcelo Lira <marcelo@openbossa.org>
-rw-r--r--typedatabase.cpp76
1 files changed, 41 insertions, 35 deletions
diff --git a/typedatabase.cpp b/typedatabase.cpp
index 98ffc0b8..4ff2128e 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<int, QList<TypeEntry*> > GroupedTypeEntries;
- GroupedTypeEntries groupedEntries;
-
- // Group type entries by revision numbers
- TypeEntryHash allEntries = tdb->allEntries();
- foreach (QList<TypeEntry*> 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<int, QList<TypeEntry*> > GroupedTypeEntries;
+ GroupedTypeEntries groupedEntries;
+
+ // Group type entries by revision numbers
+ TypeEntryHash allEntries = tdb->allEntries();
+ foreach (QList<TypeEntry*> 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<TypeEntry*>::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<TypeEntry*>::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;
}