1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-02-21 04:54:15 +01:00

[dxvk] Optimize small_vector reallocation code

This commit is contained in:
Philip Rebohle 2024-10-17 11:02:13 +02:00 committed by Philip Rebohle
parent f56b77942d
commit 43355ecd73

View File

@ -3,6 +3,10 @@
#include <cstddef>
#include <cstdint>
#include <type_traits>
#include <utility>
#include "util_bit.h"
#include "util_likely.h"
namespace dxvk {
@ -84,11 +88,11 @@ namespace dxvk {
}
void reserve(size_t n) {
n = pick_capacity(n);
if (n <= m_capacity)
if (likely(n <= m_capacity))
return;
n = pick_capacity(n);
storage* data = new storage[n];
for (size_t i = 0; i < m_size; i++) {
@ -178,12 +182,8 @@ namespace dxvk {
} u;
size_t pick_capacity(size_t n) {
size_t capacity = m_capacity;
while (capacity < n)
capacity *= 2;
return capacity;
// Pick next largest power of two for the new capacity
return size_t(1u) << ((sizeof(n) * 8u) - bit::lzcnt(n - 1));
}
T* ptr(size_t idx) {