Rewrite routing data buffers to strip old entries + sort by key to make queries not touch scattered data. Entries D,A,B,B,A,C,B --> A,A,B,B,B,C,D Index A:1 B:2 C:5 D:0 --> A:0 B:2 C:5 D:6 See 'Metrics->Key Owners & Shortcut Routing' to visualize the result of that operation.
| 8031 | // Index A:1 B:2 C:5 D:0 --> A:0 B:2 C:5 D:6 |
| 8032 | // See 'Metrics->Key Owners & Shortcut Routing' to visualize the result of that operation. |
| 8033 | static void ImGui::UpdateKeyRoutingTable(ImGuiKeyRoutingTable* rt) |
| 8034 | { |
| 8035 | ImGuiContext& g = *GImGui; |
| 8036 | rt->EntriesNext.resize(0); |
| 8037 | for (ImGuiKey key = ImGuiKey_NamedKey_BEGIN; key < ImGuiKey_NamedKey_END; key = (ImGuiKey)(key + 1)) |
| 8038 | { |
| 8039 | const int new_routing_start_idx = rt->EntriesNext.Size; |
| 8040 | ImGuiKeyRoutingData* routing_entry; |
| 8041 | for (int old_routing_idx = rt->Index[key - ImGuiKey_NamedKey_BEGIN]; old_routing_idx != -1; old_routing_idx = routing_entry->NextEntryIndex) |
| 8042 | { |
| 8043 | routing_entry = &rt->Entries[old_routing_idx]; |
| 8044 | routing_entry->RoutingCurr = routing_entry->RoutingNext; // Update entry |
| 8045 | routing_entry->RoutingNext = ImGuiKeyOwner_None; |
| 8046 | routing_entry->RoutingNextScore = 255; |
| 8047 | if (routing_entry->RoutingCurr == ImGuiKeyOwner_None) |
| 8048 | continue; |
| 8049 | rt->EntriesNext.push_back(*routing_entry); // Write alive ones into new buffer |
| 8050 | |
| 8051 | // Apply routing to owner if there's no owner already (RoutingCurr == None at this point) |
| 8052 | if (routing_entry->Mods == g.IO.KeyMods) |
| 8053 | { |
| 8054 | ImGuiKeyOwnerData* owner_data = GetKeyOwnerData(&g, key); |
| 8055 | if (owner_data->OwnerCurr == ImGuiKeyOwner_None) |
| 8056 | owner_data->OwnerCurr = routing_entry->RoutingCurr; |
| 8057 | } |
| 8058 | } |
| 8059 | |
| 8060 | // Rewrite linked-list |
| 8061 | rt->Index[key - ImGuiKey_NamedKey_BEGIN] = (ImGuiKeyRoutingIndex)(new_routing_start_idx < rt->EntriesNext.Size ? new_routing_start_idx : -1); |
| 8062 | for (int n = new_routing_start_idx; n < rt->EntriesNext.Size; n++) |
| 8063 | rt->EntriesNext[n].NextEntryIndex = (ImGuiKeyRoutingIndex)((n + 1 < rt->EntriesNext.Size) ? n + 1 : -1); |
| 8064 | } |
| 8065 | rt->Entries.swap(rt->EntriesNext); // Swap new and old indexes |
| 8066 | } |
| 8067 | |
| 8068 | // owner_id may be None/Any, but routing_id needs to be always be set, so we default to GetCurrentFocusScope(). |
| 8069 | static inline ImGuiID GetRoutingIdFromOwnerId(ImGuiID owner_id) |
nothing calls this directly
no test coverage detected