Skip to content

Conversation

@hugovk
Copy link
Member

@hugovk hugovk commented Dec 18, 2023

_isconstant() is short and only called once, we might as well inline it, it's also quicker:

python -m timeit -s "def _isconstant(v): return isinstance(v, (int, float))" "_isconstant(12.34)"
5000000 loops, best of 5: 54.1 nsec per looppython -m timeit "isinstance(12.34, (int, float))"
10000000 loops, best of 5: 38.3 nsec per loop

History:

The current one is from 2019:

def _isconstant(v):
    return isinstance(v, (int, float))

The 2013, 2to3 version was:

def _isconstant(v):
    return isinstance(v, int) or isinstance(v, float)

The original 2006, PIL 1.1.6 version was:

def _isconstant(v):
    return isinstance(v, type(0)) or isinstance(v, type(0.0))

@hugovk hugovk added the Cleanup label Dec 18, 2023
@radarhere radarhere merged commit 67890b2 into python-pillow:main Dec 18, 2023
@hugovk hugovk deleted the cleanup-imagemath-inline-isinstance branch December 18, 2023 21:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants