Commit eccd7ece by Jamie Madill Committed by Commit Bot

Use a heap for the released handle list.

This will prioritize re-allocating smaller handles. It should not affect performance in most cases, but will prefer allocating handles that are in the "fast" portion of the resource map. BUG=angleproject:1458 Change-Id: Ib2853be936f09fc1e6b5bfb870c360ce8424ab5f Reviewed-on: https://chromium-review.googlesource.com/665993 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 80823cc8
...@@ -49,9 +49,10 @@ GLuint HandleAllocator::allocate() ...@@ -49,9 +49,10 @@ GLuint HandleAllocator::allocate()
{ {
ASSERT(!mUnallocatedList.empty() || !mReleasedList.empty()); ASSERT(!mUnallocatedList.empty() || !mReleasedList.empty());
// Allocate from released list, constant time. // Allocate from released list, logarithmic time for pop_heap.
if (!mReleasedList.empty()) if (!mReleasedList.empty())
{ {
std::pop_heap(mReleasedList.begin(), mReleasedList.end());
GLuint reusedHandle = mReleasedList.back(); GLuint reusedHandle = mReleasedList.back();
mReleasedList.pop_back(); mReleasedList.pop_back();
return reusedHandle; return reusedHandle;
...@@ -77,8 +78,9 @@ GLuint HandleAllocator::allocate() ...@@ -77,8 +78,9 @@ GLuint HandleAllocator::allocate()
void HandleAllocator::release(GLuint handle) void HandleAllocator::release(GLuint handle)
{ {
// Add to released list, constant time. // Add to released list, logarithmic time for push_heap.
mReleasedList.push_back(handle); mReleasedList.push_back(handle);
std::push_heap(mReleasedList.begin(), mReleasedList.end());
} }
void HandleAllocator::reserve(GLuint handle) void HandleAllocator::reserve(GLuint handle)
......
...@@ -14,8 +14,6 @@ ...@@ -14,8 +14,6 @@
#include "angle_gl.h" #include "angle_gl.h"
#include <stack>
namespace gl namespace gl
{ {
...@@ -55,7 +53,7 @@ class HandleAllocator final : angle::NonCopyable ...@@ -55,7 +53,7 @@ class HandleAllocator final : angle::NonCopyable
// The freelist consists of never-allocated handles, stored // The freelist consists of never-allocated handles, stored
// as ranges, and handles that were previously allocated and // as ranges, and handles that were previously allocated and
// released, stored in a stack. // released, stored in a heap.
std::vector<HandleRange> mUnallocatedList; std::vector<HandleRange> mUnallocatedList;
std::vector<GLuint> mReleasedList; std::vector<GLuint> mReleasedList;
}; };
......
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