From a495b9b8845ce03bd21f021f6014e4a3b7d76df0 Mon Sep 17 00:00:00 2001 From: scrawl Date: Tue, 14 Feb 2017 07:10:01 +0100 Subject: [PATCH] Fix wasteful allocations in Store::search --- apps/openmw/mwworld/store.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/apps/openmw/mwworld/store.cpp b/apps/openmw/mwworld/store.cpp index ce41ddf94..922144814 100644 --- a/apps/openmw/mwworld/store.cpp +++ b/apps/openmw/mwworld/store.cpp @@ -38,6 +38,12 @@ namespace } return x->mX < y->mX; } + bool operator()(const ESM::Land *x, const std::pair& y) { + if (x->mX == y.first) { + return x->mY < y.second; + } + return x->mX < y.first; + } }; } @@ -438,11 +444,10 @@ namespace MWWorld } const ESM::Land *Store::search(int x, int y) const { - ESM::Land land; - land.mX = x, land.mY = y; + std::pair comp(x,y); std::vector::const_iterator it = - std::lower_bound(mStatic.begin(), mStatic.end(), &land, Compare()); + std::lower_bound(mStatic.begin(), mStatic.end(), comp, Compare()); if (it != mStatic.end() && (*it)->mX == x && (*it)->mY == y) { return *it;