Refs #28024 -- Optimized GEOSCoordSeq.tuple by avoiding superfluous index and dimension checks.

This commit is contained in:
Sergey Fedoseev 2017-04-05 13:05:03 +05:00 committed by Tim Graham
parent 14671affc3
commit d453dfb1da
1 changed files with 22 additions and 3 deletions

View File

@ -80,6 +80,25 @@ class GEOSCoordSeq(GEOSBase):
if dim < 0 or dim > 2: if dim < 0 or dim > 2:
raise GEOSException('invalid ordinate dimension "%d"' % dim) raise GEOSException('invalid ordinate dimension "%d"' % dim)
def _get_x(self, index):
return capi.cs_getx(self.ptr, index, byref(c_double()))
def _get_y(self, index):
return capi.cs_gety(self.ptr, index, byref(c_double()))
def _get_z(self, index):
return capi.cs_getz(self.ptr, index, byref(c_double()))
@property
def _point_getter(self):
return self._get_point_3d if self.dims == 3 and self._z else self._get_point_2d
def _get_point_2d(self, index):
return (self._get_x(index), self._get_y(index))
def _get_point_3d(self, index):
return (self._get_x(index), self._get_y(index), self._get_z(index))
# #### Ordinate getting and setting routines #### # #### Ordinate getting and setting routines ####
def getOrdinate(self, dimension, index): def getOrdinate(self, dimension, index):
"Return the value for the given dimension and index." "Return the value for the given dimension and index."
@ -157,7 +176,7 @@ class GEOSCoordSeq(GEOSBase):
def tuple(self): def tuple(self):
"Return a tuple version of this coordinate sequence." "Return a tuple version of this coordinate sequence."
n = self.size n = self.size
get_point = self._point_getter
if n == 1: if n == 1:
return self[0] return get_point(0)
else: return tuple(get_point(i) for i in range(n))
return tuple(self[i] for i in range(n))