Navigation Menu

Skip to content

Commit

Permalink
Performance|libdoomsday: Optimized checking of DEDRegister size
Browse files Browse the repository at this point in the history
When a map is being loaded, the size of a DEDRegister is checked
numerous times. These changes remove the big performance bottleneck
of looking up the "order" variable repeatedly from a QMap.
  • Loading branch information
skyjake committed Jul 8, 2015
1 parent 129e598 commit 38e6ccf
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions doomsday/apps/libdoomsday/src/defs/dedregister.cpp
Expand Up @@ -27,13 +27,16 @@

using namespace de;

static QString const VAR_ORDER = "order";

DENG2_PIMPL(DEDRegister)
, DENG2_OBSERVES(Record, Deletion)
, DENG2_OBSERVES(Record, Addition)
, DENG2_OBSERVES(Record, Removal)
, DENG2_OBSERVES(Variable, ChangeFrom)
{
Record *names;
ArrayValue *orderArray;
struct Key {
LookupFlags flags;
Key(LookupFlags const &f = DefaultLookup) : flags(f) {}
Expand All @@ -47,7 +50,7 @@ DENG2_PIMPL(DEDRegister)
names->audienceForDeletion() += this;

// The definitions will be stored here in the original order.
names->addArray("order");
orderArray = &names->addArray(VAR_ORDER).array();
}

~Instance()
Expand All @@ -58,14 +61,15 @@ DENG2_PIMPL(DEDRegister)
void recordBeingDeleted(Record &DENG2_DEBUG_ONLY(record))
{
DENG2_ASSERT(names == &record);
names = 0;
names = nullptr;
orderArray = nullptr;
}

void clear()
{
// As a side-effect, the lookups will be cleared, too, as the members of
// each definition record are deleted.
(*names)["order"].array().clear();
order().clear();

#ifdef DENG2_DEBUG
DENG2_ASSERT(parents.isEmpty());
Expand All @@ -84,12 +88,14 @@ DENG2_PIMPL(DEDRegister)

ArrayValue &order()
{
return (*names)["order"].array();
DENG2_ASSERT(orderArray != nullptr);
return *orderArray;
}

ArrayValue const &order() const
{
return (*names)["order"].array();
DENG2_ASSERT(orderArray != nullptr);
return *orderArray;
}

DictionaryValue &lookup(String const &keyName)
Expand Down

0 comments on commit 38e6ccf

Please sign in to comment.