feat(canvas): new buffer check color data identity#642
Open
slook wants to merge 1 commit into
Open
Conversation
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.
==toisin the new buffer push method. Only applicable ifdoubleBufferNew=True.The
ischeck is a raw pointer comparison with no module method call, no tuple unpacking, and no attribute access. It eliminates all calls toTTkColor.__eq__()in the hottest loop in the library, in favor of simply checking if the data and colors are the same objects or not.There doesn't seem to be many or any cases where the objects are different but have the same values, so this optimization doesn't appear to result in extra bytes being written to the terminal unnecessarily.
This is much faster than performing separate equality comparison operations for both the foreground and background color values for each character being pushed in the paint event, especially since it avoids the very slow
isinstance()call in the__eq__()method of color.py which was recently added in PR #638 (but even if that regression is fixed by PR #641 , then this would still be a good optimization to make anyway).