Commit 43cbe74e by jbauman@chromium.org

Use std::map to find correct index range

Instead of iterating through every range to find the one we're looking for, instead put them all in a map and find them with that. This helps performance with index buffers that contain a bunch of different ranges. BUG= TEST= Review URL: http://codereview.appspot.com/4974051 git-svn-id: https://angleproject.googlecode.com/svn/trunk@742 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 3a01d1bc
#define MAJOR_VERSION 0
#define MINOR_VERSION 0
#define BUILD_VERSION 0
#define BUILD_REVISION 740
#define BUILD_REVISION 742
#define STRINGIFY(x) #x
#define MACRO_STRINGIFY(x) STRINGIFY(x)
......
......@@ -381,24 +381,25 @@ bool StaticIndexBuffer::lookupType(GLenum type)
UINT StaticIndexBuffer::lookupRange(intptr_t offset, GLsizei count, UINT *minIndex, UINT *maxIndex)
{
for (unsigned int range = 0; range < mCache.size(); range++)
{
if (mCache[range].offset == offset && mCache[range].count == count)
{
*minIndex = mCache[range].minIndex;
*maxIndex = mCache[range].maxIndex;
IndexRange range = {offset, count};
return mCache[range].streamOffset;
}
std::map<IndexRange, IndexResult>::iterator res = mCache.find(range);
if (res == mCache.end())
{
return -1;
}
return -1;
*minIndex = res->second.minIndex;
*maxIndex = res->second.maxIndex;
return res->second.streamOffset;
}
void StaticIndexBuffer::addRange(intptr_t offset, GLsizei count, UINT minIndex, UINT maxIndex, UINT streamOffset)
{
IndexRange indexRange = {offset, count, minIndex, maxIndex, streamOffset};
mCache.push_back(indexRange);
IndexRange indexRange = {offset, count};
IndexResult indexResult = {minIndex, maxIndex, streamOffset};
mCache[indexRange] = indexResult;
}
}
......@@ -87,12 +87,28 @@ class StaticIndexBuffer : public IndexBuffer
intptr_t offset;
GLsizei count;
bool operator<(const IndexRange& rhs) const
{
if (offset != rhs.offset)
{
return offset < rhs.offset;
}
if (count != rhs.count)
{
return count < rhs.count;
}
return false;
}
};
struct IndexResult
{
UINT minIndex;
UINT maxIndex;
UINT streamOffset;
};
std::vector<IndexRange> mCache;
std::map<IndexRange, IndexResult> mCache;
};
class IndexDataManager
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment