Don't reserve more space than we need

This commit is contained in:
Luke Benstead 2019-03-06 08:31:06 +00:00
parent 2ac9cac22d
commit 3e1ed8a5f7
2 changed files with 8 additions and 3 deletions

View File

@ -1,5 +1,6 @@
#include <float.h>
#include <stdio.h>
#include <assert.h>
#ifdef _arch_dreamcast
#include <dc/pvr.h>
@ -165,6 +166,8 @@ void clipTriangleStrip2(AlignedVector* vertices, uint32_t offset, uint8_t fladeS
uint32_t i = 0;
/* Skip the header */
assert(offset < vertices->size);
ClipVertex* header = (ClipVertex*) aligned_vector_at(vertices, offset);
ClipVertex* vertex = header + 1;
@ -174,6 +177,8 @@ void clipTriangleStrip2(AlignedVector* vertices, uint32_t offset, uint8_t fladeS
/* Start at 3 due to the header */
for(i = 3; i < count; ++i, ++triangle) {
assert(offset + i < vertices->size);
vertex = aligned_vector_at(vertices, offset + i);
uint8_t even = (triangle % 2) == 0;

View File

@ -1,6 +1,7 @@
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <assert.h>
#if defined(__APPLE__) || defined(__WIN32__)
/* Linux + Kos define this, OSX does not, so just use malloc there */
@ -64,9 +65,7 @@ void* aligned_vector_resize(AlignedVector* vector, const unsigned int element_co
}
if(vector->capacity < element_count) {
/* Reserve more than we need so that a subsequent push_back doesn't trigger yet another
* resize */
aligned_vector_reserve(vector, (int) ceil(((float)element_count) * 1.5f));
aligned_vector_reserve(vector, element_count);
}
vector->size = element_count;
@ -79,6 +78,7 @@ void* aligned_vector_resize(AlignedVector* vector, const unsigned int element_co
}
void* aligned_vector_at(const AlignedVector* vector, const unsigned int index) {
assert(index < vector->size);
return &vector->data[index * vector->element_size];
}