From f379dc28a3f84d1c6805ae74bd37d9a9130e34e7 Mon Sep 17 00:00:00 2001 From: thedmd Date: Tue, 19 Jan 2021 20:23:06 +0100 Subject: [PATCH] ImBitArray: Rename ClearBits() to ClearAllBits() and add SetAllBits(). ImBitArraySetBitRange work on range [n..n2) instead of [n..n2] --- imgui_internal.h | 8 +++++--- imgui_tables.cpp | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/imgui_internal.h b/imgui_internal.h index e1908335..da4e6614 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -466,8 +466,9 @@ struct IMGUI_API ImRect inline bool ImBitArrayTestBit(const ImU32* arr, int n) { ImU32 mask = (ImU32)1 << (n & 31); return (arr[n >> 5] & mask) != 0; } inline void ImBitArrayClearBit(ImU32* arr, int n) { ImU32 mask = (ImU32)1 << (n & 31); arr[n >> 5] &= ~mask; } inline void ImBitArraySetBit(ImU32* arr, int n) { ImU32 mask = (ImU32)1 << (n & 31); arr[n >> 5] |= mask; } -inline void ImBitArraySetBitRange(ImU32* arr, int n, int n2) +inline void ImBitArraySetBitRange(ImU32* arr, int n, int n2) // Works on range [n..n2) { + n2--; while (n <= n2) { int a_mod = (n & 31); @@ -485,11 +486,12 @@ struct IMGUI_API ImBitArray { ImU32 Storage[(BITCOUNT + 31) >> 5]; ImBitArray() { } - void ClearBits() { memset(Storage, 0, sizeof(Storage)); } + void ClearAllBits() { memset(Storage, 0, sizeof(Storage)); } + void SetAllBits() { memset(Storage, 255, sizeof(Storage)); } bool TestBit(int n) const { IM_ASSERT(n < BITCOUNT); return ImBitArrayTestBit(Storage, n); } void SetBit(int n) { IM_ASSERT(n < BITCOUNT); ImBitArraySetBit(Storage, n); } void ClearBit(int n) { IM_ASSERT(n < BITCOUNT); ImBitArrayClearBit(Storage, n); } - void SetBitRange(int n1, int n2) { ImBitArraySetBitRange(Storage, n1, n2); } + void SetBitRange(int n, int n2) { ImBitArraySetBitRange(Storage, n, n2); } // Works on range [n..n2) }; // Helper: ImBitVector diff --git a/imgui_tables.cpp b/imgui_tables.cpp index 482e3ac7..adc0d942 100644 --- a/imgui_tables.cpp +++ b/imgui_tables.cpp @@ -2285,8 +2285,8 @@ void ImGui::TableMergeDrawChannels(ImGuiTable* table) g.DrawChannelsTempMergeBuffer.resize(splitter->_Count - LEADING_DRAW_CHANNELS); // Use shared temporary storage so the allocation gets amortized ImDrawChannel* dst_tmp = g.DrawChannelsTempMergeBuffer.Data; ImBitArray remaining_mask; // We need 132-bit of storage - remaining_mask.ClearBits(); - remaining_mask.SetBitRange(LEADING_DRAW_CHANNELS, splitter->_Count - 1); + remaining_mask.ClearAllBits(); + remaining_mask.SetBitRange(LEADING_DRAW_CHANNELS, splitter->_Count); remaining_mask.ClearBit(table->Bg2DrawChannelUnfrozen); IM_ASSERT(has_freeze_v == false || table->Bg2DrawChannelUnfrozen != TABLE_DRAW_CHANNEL_BG2_FROZEN); int remaining_count = splitter->_Count - (has_freeze_v ? LEADING_DRAW_CHANNELS + 1 : LEADING_DRAW_CHANNELS);