Replace unordered_map by map for storing objects

For small amount of items it gives better performance for find by key
for update.
cherry-pick-f6619658
elsid 4 years ago
parent 22c2f106b7
commit ed91cf9397
No known key found for this signature in database
GPG Key ID: B845CB9FEE18AB40

@ -12,13 +12,12 @@ namespace DetourNavigator
bool RecastMeshManager::addObject(const ObjectId id, const btCollisionShape& shape, const btTransform& transform,
const AreaType areaType)
{
const auto object = mObjects.lower_bound(id);
if (object != mObjects.end() && object->first == id)
return false;
const auto iterator = mObjectsOrder.emplace(mObjectsOrder.end(),
OscillatingRecastMeshObject(RecastMeshObject(shape, transform, areaType), mRevision + 1));
if (!mObjects.emplace(id, iterator).second)
{
mObjectsOrder.erase(iterator);
return false;
}
mObjects.emplace_hint(object, id, iterator);
++mRevision;
return true;
}

@ -13,7 +13,6 @@
#include <list>
#include <map>
#include <optional>
#include <unordered_map>
class btCollisionShape;
@ -67,7 +66,7 @@ namespace DetourNavigator
RecastMeshBuilder mMeshBuilder;
TileBounds mTileBounds;
std::list<OscillatingRecastMeshObject> mObjectsOrder;
std::unordered_map<ObjectId, std::list<OscillatingRecastMeshObject>::iterator> mObjects;
std::map<ObjectId, std::list<OscillatingRecastMeshObject>::iterator> mObjects;
std::list<Water> mWaterOrder;
std::map<osg::Vec2i, std::list<Water>::iterator> mWater;
std::optional<Report> mLastNavMeshReportedChange;

Loading…
Cancel
Save