From fb9ab893fa96641e7325fa133c46d9ab5aef77ca Mon Sep 17 00:00:00 2001 From: cam900 Date: Thu, 2 Jun 2022 01:17:21 +0900 Subject: [PATCH] Add ImVector fill function --- extern/imgui_patched/imgui.h | 1 + extern/imgui_patched/imgui_internal.h | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/extern/imgui_patched/imgui.h b/extern/imgui_patched/imgui.h index fef6dba4..7249c540 100644 --- a/extern/imgui_patched/imgui.h +++ b/extern/imgui_patched/imgui.h @@ -1880,6 +1880,7 @@ struct ImVector inline T& back() { IM_ASSERT(Size > 0); return Data[Size - 1]; } inline const T& back() const { IM_ASSERT(Size > 0); return Data[Size - 1]; } inline void swap(ImVector& rhs) { int rhs_size = rhs.Size; rhs.Size = Size; Size = rhs_size; int rhs_cap = rhs.Capacity; rhs.Capacity = Capacity; Capacity = rhs_cap; T* rhs_data = rhs.Data; rhs.Data = Data; Data = rhs_data; } + inline void fill(const T v) { for (int n = 0; n < Size; n++) Data[n] = v; } 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; } diff --git a/extern/imgui_patched/imgui_internal.h b/extern/imgui_patched/imgui_internal.h index be3ab922..d7270373 100644 --- a/extern/imgui_patched/imgui_internal.h +++ b/extern/imgui_patched/imgui_internal.h @@ -605,10 +605,10 @@ struct IMGUI_API ImBitVector ImVector Storage; int BitCount = 0; ImBitVector(int sz = 0) { if (sz > 0) { Create(sz); } } - void Create(int sz) { BitCount = sz; Storage.resize((sz + 31) >> 5); memset(Storage.Data, 0, (size_t)Storage.Size * sizeof(Storage.Data[0])); } + void Create(int sz) { BitCount = sz; Storage.resize((sz + 31) >> 5); Storage.fill(0); } void Clear() { Storage.clear(); } - void ClearAllBits() { IM_ASSERT(Storage.Size > 0); memset(Storage.Data, 0, (size_t)Storage.Size * sizeof(Storage.Data[0])); } - void SetAllBits() { IM_ASSERT(Storage.Size > 0); memset(Storage.Data, 255, (size_t)Storage.Size * sizeof(Storage.Data[0])); } + void ClearAllBits() { Storage.fill(0); } + void SetAllBits() { Storage.fill(~0); } bool TestBit(int n) const { IM_ASSERT(n >= 0 && n < BitCount); return ImBitArrayTestBit(Storage.Data, n); } void SetBit(int n) { IM_ASSERT(n >= 0 && n < BitCount); ImBitArraySetBit(Storage.Data, n); } void SetBitRange(int n, int n2) { IM_ASSERT(n >= 0 && n < BitCount && n2 > n && n2 <= BitCount); ImBitArraySetBitRange(Storage.Data, n, n2); } // Works on range [n..n2)