summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Fedoseev <fedoseev.sergey@gmail.com>2017-04-09 08:18:56 +0500
committerSergey Fedoseev <fedoseev.sergey@gmail.com>2017-04-13 11:30:26 +0500
commit6d5bb6ae9e7928155a0035e936ba74ac9c52e409 (patch)
tree4f097dd032cf7ac6b0c8ff7bd36e945b2fe27f69
parentea542a9c7239b5b665797b7c809f1aceb0b412cf (diff)
Refs #28024 -- Optimized LineString.__init__() by avoiding superfluous index and dimension checks.
-rw-r--r--django/contrib/gis/geos/linestring.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/django/contrib/gis/geos/linestring.py b/django/contrib/gis/geos/linestring.py
index 9f98ed7e23..eb339658e9 100644
--- a/django/contrib/gis/geos/linestring.py
+++ b/django/contrib/gis/geos/linestring.py
@@ -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.