Skip to content

PERF: Faster transform direction if already passed an Enum #1205

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 19, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions pyproj/_transformer.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ dy_dphi: List[float]
Partial derivative of coordinate.
"""

cdef PJ_DIRECTION get_pj_direction(object direction) except *:
# optimized lookup to avoid creating a new instance every time
# gh-1205
try:
return _PJ_DIRECTION_MAP[direction]
except KeyError:
direction = TransformDirection.create(direction)
return _PJ_DIRECTION_MAP[direction]


cdef class _TransformerGroup:
def __cinit__(self):
self.context = NULL
Expand Down Expand Up @@ -627,9 +637,7 @@ cdef class _Transformer(Base):
):
if self.id == "noop":
return

tmp_pj_direction = _PJ_DIRECTION_MAP[TransformDirection.create(direction)]
cdef PJ_DIRECTION pj_direction = <PJ_DIRECTION>tmp_pj_direction
cdef PJ_DIRECTION pj_direction = get_pj_direction(direction)
cdef PyBuffWriteManager xbuff = PyBuffWriteManager(inx)
cdef PyBuffWriteManager ybuff = PyBuffWriteManager(iny)

Expand Down Expand Up @@ -718,8 +726,7 @@ cdef class _Transformer(Base):
):
if self.id == "noop":
return
tmp_pj_direction = _PJ_DIRECTION_MAP[TransformDirection.create(direction)]
cdef PJ_DIRECTION pj_direction = <PJ_DIRECTION>tmp_pj_direction
cdef PJ_DIRECTION pj_direction = get_pj_direction(direction)
# private function to itransform function
cdef double *x
cdef double *y
Expand Down Expand Up @@ -815,8 +822,7 @@ cdef class _Transformer(Base):
bint errcheck,
object direction,
):
tmp_pj_direction = _PJ_DIRECTION_MAP[TransformDirection.create(direction)]
cdef PJ_DIRECTION pj_direction = <PJ_DIRECTION>tmp_pj_direction
cdef PJ_DIRECTION pj_direction = get_pj_direction(direction)

if self.id == "noop" or pj_direction == PJ_IDENT:
return (left, bottom, right, top)
Expand Down