optimise hash table access for better performance

This commit is contained in:
Ian Curtis 2016-05-19 19:04:44 +00:00
parent ff8d311dcc
commit a79fd2786a
2 changed files with 10 additions and 9 deletions

View file

@ -2,7 +2,7 @@
#include "PolyHeader.h"
#include "Texture.h"
#include "Vec.h"
#include <cmath> // needed by gcc
#include <cmath>
#include <algorithm>
#include <limits>
@ -283,9 +283,9 @@ bool CNew3D::DrawModel(UINT32 modelAddr)
// try to find meshes in the rom cache
m->meshes = m_romMap[modelAddr]; // will create an entry with a null pointer if empty
if (m_romMap.count(modelAddr)) {
m->meshes = m_romMap[modelAddr];
if (m->meshes) {
cached = true;
}
else {

View file

@ -31,9 +31,11 @@ std::shared_ptr<Texture> TextureSheet::BindTexture(const UINT16* src, int format
index = ToIndex(x, y);
if (m_texMap[format&TEXTURE_DEBUG_MASK].count(index) == 0) {
auto range = m_texMap[format&TEXTURE_DEBUG_MASK].equal_range(index);
//no textures at this position or format so add it to the map
if (range.first == range.second) {
// nothing found so create a new texture
std::shared_ptr<Texture> t(new Texture());
m_texMap[format&TEXTURE_DEBUG_MASK].insert(std::pair<int, std::shared_ptr<Texture>>(index, t));
@ -41,10 +43,8 @@ std::shared_ptr<Texture> TextureSheet::BindTexture(const UINT16* src, int format
return t;
}
else {
//scan for duplicates
//only texture width/height and wrap modes can change here. Since key is based on x/y pos, and each map is a separate format
auto range = m_texMap[format&TEXTURE_DEBUG_MASK].equal_range(index);
// iterate to try and find a match
for (auto it = range.first; it != range.second; ++it) {
@ -57,10 +57,11 @@ std::shared_ptr<Texture> TextureSheet::BindTexture(const UINT16* src, int format
}
}
// nothing found so create a new entry
std::shared_ptr<Texture> t(new Texture());
m_texMap[format&TEXTURE_DEBUG_MASK].insert(std::pair<int, std::shared_ptr<Texture>>(index, t));
t->UploadTexture(src, m_temp.data(), format, mirrorU, mirrorV, x, y, width, height);
return t;
}
}