Return cached element when set existing

pull/593/head
elsid 4 years ago
parent 05d6f6ac25
commit f2ebad5115
No known key found for this signature in database
GPG Key ID: B845CB9FEE18AB40

@ -77,7 +77,7 @@ namespace
EXPECT_EQ(result.get(), (NavMeshDataRef {mData, 1}));
}
TEST_F(DetourNavigatorNavMeshTilesCacheTest, set_existing_element_should_throw_exception)
TEST_F(DetourNavigatorNavMeshTilesCacheTest, set_existing_element_should_return_cached_element)
{
const std::size_t navMeshDataSize = 1;
const std::size_t navMeshKeySize = cRecastMeshKeySize;
@ -87,10 +87,9 @@ namespace
NavMeshData anotherNavMeshData {anotherData, 1};
cache.set(mAgentHalfExtents, mTilePosition, mRecastMesh, mOffMeshConnections, std::move(mNavMeshData));
EXPECT_THROW(
cache.set(mAgentHalfExtents, mTilePosition, mRecastMesh, mOffMeshConnections, std::move(anotherNavMeshData)),
InvalidArgument
);
const auto result = cache.set(mAgentHalfExtents, mTilePosition, mRecastMesh, mOffMeshConnections, std::move(anotherNavMeshData));
ASSERT_TRUE(result);
EXPECT_EQ(result.get(), (NavMeshDataRef {mData, 1}));
}
TEST_F(DetourNavigatorNavMeshTilesCacheTest, get_should_return_cached_value)

@ -576,17 +576,8 @@ namespace DetourNavigator
return navMeshCacheItem->lock()->removeTile(changedTile);
}
try
{
cachedNavMeshData = navMeshTilesCache.set(agentHalfExtents, changedTile, *recastMesh,
offMeshConnections, std::move(navMeshData));
}
catch (const InvalidArgument&)
{
cachedNavMeshData = navMeshTilesCache.get(agentHalfExtents, changedTile, *recastMesh,
offMeshConnections);
cached = static_cast<bool>(cachedNavMeshData);
}
cachedNavMeshData = navMeshTilesCache.set(agentHalfExtents, changedTile, *recastMesh,
offMeshConnections, std::move(navMeshData));
if (!cachedNavMeshData)
{

@ -1,5 +1,4 @@
#include "navmeshtilescache.hpp"
#include "exceptions.hpp"
#include <osg/Stats>
@ -68,7 +67,10 @@ namespace DetourNavigator
if (!emplaced.second)
{
mFreeItems.erase(iterator);
throw InvalidArgument("Set existing cache value");
acquireItemUnsafe(emplaced.first->second);
++mGetCount;
++mHitCount;
return Value(*this, emplaced.first->second);
}
iterator->mNavMeshData = std::move(value);

Loading…
Cancel
Save