Convert window list to doubly-linked and fix restack prev pointer bug - #46
Open
jEsuSdA wants to merge 1 commit into
Open
Convert window list to doubly-linked and fix restack prev pointer bug#46jEsuSdA wants to merge 1 commit into
jEsuSdA wants to merge 1 commit into
Conversation
Currently the window list is singly-linked, so restack_win() and finish_destroy_win() must scan the entire list to find the previous element. This is O(n) for both operations. Add a prev pointer to the win struct and maintain it correctly: - add_win(): sets prev when inserting at the head or after another window - restack_win(): unhooks and rehooks using prev directly, no linear scan This also fixes a subtle bug in restack_win(): when inserting at the end of the list (new_above not found), the old code could leave the prev pointer inconsistent, causing finish_destroy_win() to corrupt the list head and paint_all() to traverse an empty list, resulting in a grey screen. finish_destroy_win() now uses the prev pointer to unlink in O(1) instead of scanning from the head each time.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Converts the window list from singly-linked to doubly-linked, eliminating O(n) scans in
restack_win()andfinish_destroy_win(). Also fixes a subtle bug that could cause grey screen regions when restacking windows.Problem
The window list is currently singly-linked. Both
restack_win()andfinish_destroy_win()must scan the entire list to find the previous element:restack_win()scans twice (unhook + rehook)finish_destroy_win()scans once per destroyed windowAdditionally,
restack_win()has a subtle bug when inserting at the end of the list: the previous pointer of the former last node is not updated correctly, which can corrupt the list head pointer. Whenfinish_destroy_win()later frees a window at the end,paint_all()may traverse an empty list and paint nothing → grey screen.Solution
Add a
prevpointer to thewinstruct and maintain it correctly:add_win(): setsprevwhen inserting at the head or after another windowrestack_win(): unhooks and rehooks usingprevdirectly, no linear scan. Tracksnew_predduring the rehook loop to correctly setprevwhen inserting at the endfinish_destroy_win(): usesprevpointer to unlink in O(1) instead of scanning from the headChanges
cm-window.h— addsstruct _win *prevfieldfastcompmgr.c— updatesadd_win(),restack_win(),finish_destroy_win()Scope
make clean && makeproduces zero warnings, zero errorsImpact
restack_win()andfinish_destroy_win()are now O(1) instead of O(n)