[PR #15782] Modernize CommandHistory and switch to int32 #30738

Closed
opened 2026-01-31 09:42:40 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/microsoft/terminal/pull/15782

State: closed
Merged: Yes


This commit slightly modernizes CommandHistory by leaning more heavily
on the STL container functionalities. For one, it uses for-range
iterations to loop through _commands instead of using GetNth
on every iteration. Another major improvement however is that
the code previously copied entire CommandHistory instances out of
the linked list s_historyLists, then removed the slot and copied
(not moved!) that instance into the front again. Now it uses the
splice function from std::list to do it in O(1) and virtually
cost-free.

Another major improvement (and the one I'm personally interested in)
is the switch from SHORT to int32_t. This will greatly simplify
the implementation of the future COOKED_READ_DATA class, as the
larger integer type will remove worries about over/underflow.
For instance, we can then just blindly increment/decrement the history
position and then only later clamp it to the expected range.

Validation Steps Performed

  • Existing history tests
  • History cycling with F8
  • Navigating history with F7
**Original Pull Request:** https://github.com/microsoft/terminal/pull/15782 **State:** closed **Merged:** Yes --- This commit slightly modernizes `CommandHistory` by leaning more heavily on the STL container functionalities. For one, it uses for-range iterations to loop through `_commands` instead of using `GetNth` on every iteration. Another major improvement however is that the code previously copied entire `CommandHistory` instances out of the linked list `s_historyLists`, then removed the slot and copied (not moved!) that instance into the front again. Now it uses the `splice` function from `std::list` to do it in `O(1)` and virtually cost-free. Another major improvement (and the one I'm personally interested in) is the switch from `SHORT` to `int32_t`. This will greatly simplify the implementation of the future `COOKED_READ_DATA` class, as the larger integer type will remove worries about over/underflow. For instance, we can then just blindly increment/decrement the history position and then only later clamp it to the expected range. ## Validation Steps Performed * Existing history tests ✅ * History cycling with F8 ✅ * Navigating history with F7 ✅
claunia added the pull-request label 2026-01-31 09:42:40 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#30738