Only call text_layout once in getmask2#7206
Merged
hugovk merged 2 commits intopython-pillow:mainfrom Jun 13, 2023
Merged
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.
Helps #6618
Backstory
The following is an earlier version of
ImageFont'sgetmask2(), as described in the quoted comment.Pillow/src/PIL/ImageFont.py
Lines 752 to 777 in 3cfdef3
#6618 (comment)
#7059 removed the deprecated fill parameter. So here is the current version of
ImageFont'sgetmask2().Pillow/src/PIL/ImageFont.py
Lines 554 to 575 in 1fc8d82
This is the only place that
font.renderis called.Change
So I added a change to make
font.getsizea builtin part offont.render, meaning thattext_layoutis not called once by each, but only once.From my tests, this causes
getmask2to be 10% faster.There is an awkward part of this change though - the _imagingft extension is not connected to the C code for creating new images. I couldn't call
ImagingNewDirtyandImagingFill. Despite the quoted comment's expectation that this could all be done in C, it didn't realise that our C code is actually split up into these extensions. Instead, I've passedImage.core.fillinto C, to then be called byPyObject_CallFunction.