summaryrefslogtreecommitdiff
path: root/indra/llcommon/llinstancetracker.cpp
diff options
context:
space:
mode:
authorNat Goodspeed <nat@lindenlab.com>2011-09-06 22:07:49 -0400
committerNat Goodspeed <nat@lindenlab.com>2011-09-06 22:07:49 -0400
commit8c6f752982e83a50e328b9c83f762721f38836d7 (patch)
tree6954c6e48896ed78d98e7a91c6ee35e98647a965 /indra/llcommon/llinstancetracker.cpp
parent0ab6eee0996c78d32b722157140cea5a21a5e460 (diff)
STORM-1541: Hoist LLInstanceTracker::getMap_() to base getStatic().
Generalize the notion of getting some chunk of "static" storage: introduce LLInstanceTrackerBase::getStatic() template method. Define StaticData struct containing the InstanceMap (or InstanceSet, for that specialization) along with the S32 that caused the VS2010 linker so much grief. Completely eliminate that S32 as an actual class-static member, qualifying all references with the struct returned by getStatic(). In LLInstanceTrackerBase::getInstances(), use one std::map lookup instead of three.
Diffstat (limited to 'indra/llcommon/llinstancetracker.cpp')
-rw-r--r--indra/llcommon/llinstancetracker.cpp19
1 files changed, 10 insertions, 9 deletions
diff --git a/indra/llcommon/llinstancetracker.cpp b/indra/llcommon/llinstancetracker.cpp
index f576204511..5dc3ea5d7b 100644
--- a/indra/llcommon/llinstancetracker.cpp
+++ b/indra/llcommon/llinstancetracker.cpp
@@ -35,14 +35,15 @@
//static
void * & LLInstanceTrackerBase::getInstances(std::type_info const & info)
{
- static std::map<std::string, void *> instances;
+ typedef std::map<std::string, void *> InstancesMap;
+ static InstancesMap instances;
- std::string k = info.name();
- if(instances.find(k) == instances.end())
- {
- instances[k] = NULL;
- }
-
- return instances[k];
+ // std::map::insert() is just what we want here. You attempt to insert a
+ // (key, value) pair. If the specified key doesn't yet exist, it inserts
+ // the pair and returns a std::pair of (iterator, true). If the specified
+ // key DOES exist, insert() simply returns (iterator, false). One lookup
+ // handles both cases.
+ return instances.insert(InstancesMap::value_type(info.name(),
+ InstancesMap::mapped_type()))
+ .first->second;
}
-