Commit c57e5366 by Nicolas Capens

Allocate object names into an unordered set.

Bug 19219444 Change-Id: Ic100f0bfe64b1f92f13c4f6a413e30095b7b5a6c Reviewed-on: https://swiftshader-review.googlesource.com/4985Tested-by: 's avatarNicolas Capens <capn@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <capn@google.com>
parent 5834c680
......@@ -15,7 +15,10 @@
#ifndef gl_NameSpace_hpp
#define gl_NameSpace_hpp
#include <vector>
#include "Object.hpp"
#include <unordered_set>
#include <algorithm>
typedef unsigned int GLuint;
......@@ -23,51 +26,36 @@ namespace gl
{
template<class ObjectType, GLuint baseName = 1>
class NameSpace
class NameSpace : std::unordered_set<GLuint>
{
public:
NameSpace() : baseValue(baseName), nextValue(baseName)
NameSpace() : freeName(baseName)
{
}
GLuint allocate()
{
if(freeValues.size())
{
GLuint handle = freeValues.back();
freeValues.pop_back();
GLuint name = freeName;
return handle;
while(find(name) != end())
{
name++;
}
return nextValue++;
insert(name);
freeName = name + 1;
return name;
}
void release(GLuint handle)
void release(GLuint name)
{
if(handle == nextValue - 1)
{
// Don't drop below base value
if(nextValue > baseValue)
{
nextValue--;
}
}
else
{
// Only free handles that we own - don't drop below the base value
if(handle >= baseValue)
{
freeValues.push_back(handle);
}
}
erase(name);
freeName = std::min(name, freeName);
}
private:
GLuint baseValue;
GLuint nextValue;
typedef std::vector<GLuint> HandleList;
HandleList freeValues;
GLuint freeName;
};
}
......
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