Refs #28024 -- Optimized LineString.__init__() by avoiding superfluous index and dimension checks.

This commit is contained in:
Sergey Fedoseev 2017-04-09 08:18:56 +05:00
parent ea542a9c72
commit 6d5bb6ae9e
1 changed files with 6 additions and 4 deletions

View File

@ -73,16 +73,18 @@ class LineString(LinearGeometryMixin, GEOSGeometry):
numpy_coords = True
# Creating a coordinate sequence object because it is easier to
# set the points using GEOSCoordSeq.__setitem__().
# set the points using its methods.
cs = GEOSCoordSeq(capi.create_cs(ncoords, ndim), z=bool(ndim == 3))
point_setter = cs._set_point_3d if ndim == 3 else cs._set_point_2d
for i in range(ncoords):
if numpy_coords:
cs[i] = coords[i, :]
point_coords = coords[i, :]
elif isinstance(coords[i], Point):
cs[i] = coords[i].tuple
point_coords = coords[i].tuple
else:
cs[i] = coords[i]
point_coords = coords[i]
point_setter(i, point_coords)
# Calling the base geometry initialization with the returned pointer
# from the function.