Skip to content

Commit 9d704d9

Browse files
committed
Internals: wrapped ImQsort() in an inline function + added a define guard.
1 parent 66f0fb9 commit 9d704d9

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

imgui.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -1954,8 +1954,7 @@ void ImGuiStorage::BuildSortByKey()
19541954
return 0;
19551955
}
19561956
};
1957-
if (Data.Size > 1)
1958-
ImQsort(Data.Data, (size_t)Data.Size, sizeof(ImGuiStoragePair), StaticFunc::PairCompareByID);
1957+
ImQsort(Data.Data, (size_t)Data.Size, sizeof(ImGuiStoragePair), StaticFunc::PairCompareByID);
19591958
}
19601959

19611960
int ImGuiStorage::GetInt(ImGuiID key, int default_val) const
@@ -4304,8 +4303,7 @@ static void AddWindowToSortBuffer(ImVector<ImGuiWindow*>* out_sorted_windows, Im
43044303
if (window->Active)
43054304
{
43064305
int count = window->DC.ChildWindows.Size;
4307-
if (count > 1)
4308-
ImQsort(window->DC.ChildWindows.Data, (size_t)count, sizeof(ImGuiWindow*), ChildWindowComparer);
4306+
ImQsort(window->DC.ChildWindows.Data, (size_t)count, sizeof(ImGuiWindow*), ChildWindowComparer);
43094307
for (int i = 0; i < count; i++)
43104308
{
43114309
ImGuiWindow* child = window->DC.ChildWindows[i];

imgui_internal.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,9 @@ static inline ImGuiID ImHash(const void* data, int size, ImU32 seed = 0) { ret
302302
#endif
303303

304304
// Helpers: Sorting
305-
#define ImQsort qsort
305+
#ifndef ImQsort
306+
static inline void ImQsort(void* base, size_t count, size_t size_of_element, int(IMGUI_CDECL *compare_func)(void const*, void const*)) { if (count > 1) qsort(base, count, size_of_element, compare_func); }
307+
#endif
306308

307309
// Helpers: Color Blending
308310
IMGUI_API ImU32 ImAlphaBlendColors(ImU32 col_a, ImU32 col_b);
@@ -409,8 +411,8 @@ static inline double ImLog(double x) { return log(x); }
409411
static inline int ImAbs(int x) { return x < 0 ? -x : x; }
410412
static inline float ImAbs(float x) { return fabsf(x); }
411413
static inline double ImAbs(double x) { return fabs(x); }
412-
static inline float ImSign(float x) { return (x < 0.0f) ? -1.0f : ((x > 0.0f) ? 1.0f : 0.0f); } // Sign operator - returns -1, 0 or 1 based on sign of argument
413-
static inline double ImSign(double x) { return (x < 0.0) ? -1.0 : ((x > 0.0) ? 1.0 : 0.0); }
414+
static inline float ImSign(float x) { return (x < 0.0f) ? -1.0f : (x > 0.0f) ? 1.0f : 0.0f; } // Sign operator - returns -1, 0 or 1 based on sign of argument
415+
static inline double ImSign(double x) { return (x < 0.0) ? -1.0 : (x > 0.0) ? 1.0 : 0.0; }
414416
#ifdef IMGUI_ENABLE_SSE
415417
static inline float ImRsqrt(float x) { return _mm_cvtss_f32(_mm_rsqrt_ss(_mm_set_ss(x))); }
416418
#else

imgui_widgets.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -7247,8 +7247,7 @@ bool ImGui::BeginTabBarEx(ImGuiTabBar* tab_bar, const ImRect& tab_bar_bb, ImG
72477247

72487248
// Ensure correct ordering when toggling ImGuiTabBarFlags_Reorderable flag, or when a new tab was added while being not reorderable
72497249
if ((flags & ImGuiTabBarFlags_Reorderable) != (tab_bar->Flags & ImGuiTabBarFlags_Reorderable) || (tab_bar->TabsAddedNew && !(flags & ImGuiTabBarFlags_Reorderable)))
7250-
if (tab_bar->Tabs.Size > 1)
7251-
ImQsort(tab_bar->Tabs.Data, tab_bar->Tabs.Size, sizeof(ImGuiTabItem), TabItemComparerByBeginOrder);
7250+
ImQsort(tab_bar->Tabs.Data, tab_bar->Tabs.Size, sizeof(ImGuiTabItem), TabItemComparerByBeginOrder);
72527251
tab_bar->TabsAddedNew = false;
72537252

72547253
// Flags

0 commit comments

Comments
 (0)