From 7ffbcfe46725985e62665d637add60e091a5e64c Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 9 Jan 2019 15:56:37 +0100 Subject: [PATCH] ImVector: Made reserve() another silly one-liner. It's not longer than other functions and our weird obsessions deserve to be carried with stringent consistence. + Comments --- imgui.h | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/imgui.h b/imgui.h index d790b6f4..3cac4336 100644 --- a/imgui.h +++ b/imgui.h @@ -1200,19 +1200,7 @@ struct ImVector inline int _grow_capacity(int sz) const { int new_capacity = Capacity ? (Capacity + Capacity/2) : 8; return new_capacity > sz ? new_capacity : sz; } inline void resize(int new_size) { if (new_size > Capacity) reserve(_grow_capacity(new_size)); Size = new_size; } inline void resize(int new_size, const T& v) { if (new_size > Capacity) reserve(_grow_capacity(new_size)); if (new_size > Size) for (int n = Size; n < new_size; n++) memcpy(&Data[n], &v, sizeof(v)); Size = new_size; } - inline void reserve(int new_capacity) - { - if (new_capacity <= Capacity) - return; - T* new_data = (T*)ImGui::MemAlloc((size_t)new_capacity * sizeof(T)); - if (Data) - { - memcpy(new_data, Data, (size_t)Size * sizeof(T)); - ImGui::MemFree(Data); - } - Data = new_data; - Capacity = new_capacity; - } + inline void reserve(int new_capacity) { if (new_capacity <= Capacity) return; T* new_data = (T*)ImGui::MemAlloc((size_t)new_capacity * sizeof(T)); if (Data) { memcpy(new_data, Data, (size_t)Size * sizeof(T)); ImGui::MemFree(Data); } Data = new_data; Capacity = new_capacity; } // NB: It is illegal to call push_back/push_front/insert with a reference pointing inside the ImVector data itself! e.g. v.push_back(v[10]) is forbidden. inline void push_back(const T& v) { if (Size == Capacity) reserve(_grow_capacity(Size + 1)); memcpy(&Data[Size], &v, sizeof(v)); Size++; }