Fixed / removed unncessary allocation in Render()

This commit is contained in:
ocornut 2015-02-01 14:42:09 +00:00
parent bde3f6b90d
commit 85763150e8

View File

@ -984,6 +984,7 @@ struct ImGuiState
// Render // Render
ImVector<ImDrawList*> RenderDrawLists; ImVector<ImDrawList*> RenderDrawLists;
ImVector<ImGuiWindow*> RenderSortedWindows;
// Widget state // Widget state
ImGuiTextEditState InputTextState; ImGuiTextEditState InputTextState;
@ -1866,18 +1867,18 @@ void ImGui::Render()
// Sort the window list so that all child windows are after their parent // Sort the window list so that all child windows are after their parent
// We cannot do that on FocusWindow() because childs may not exist yet // We cannot do that on FocusWindow() because childs may not exist yet
ImVector<ImGuiWindow*> sorted_windows; g.RenderSortedWindows.resize(0);
sorted_windows.reserve(g.Windows.size()); g.RenderSortedWindows.reserve(g.Windows.size());
for (size_t i = 0; i != g.Windows.size(); i++) for (size_t i = 0; i != g.Windows.size(); i++)
{ {
ImGuiWindow* window = g.Windows[i]; ImGuiWindow* window = g.Windows[i];
if (window->Flags & ImGuiWindowFlags_ChildWindow) // if a child is visible its parent will add it if (window->Flags & ImGuiWindowFlags_ChildWindow) // if a child is visible its parent will add it
if (window->Visible) if (window->Visible)
continue; continue;
AddWindowToSortedBuffer(window, sorted_windows); AddWindowToSortedBuffer(window, g.RenderSortedWindows);
} }
IM_ASSERT(g.Windows.size() == sorted_windows.size()); // We done something wrong IM_ASSERT(g.Windows.size() == g.RenderSortedWindows.size()); // We done something wrong
g.Windows.swap(sorted_windows); g.Windows.swap(g.RenderSortedWindows);
// Clear data for next frame // Clear data for next frame
g.IO.MouseWheel = 0.0f; g.IO.MouseWheel = 0.0f;