From 6d5bb6ae9e7928155a0035e936ba74ac9c52e409 Mon Sep 17 00:00:00 2001 From: Sergey Fedoseev Date: Sun, 9 Apr 2017 08:18:56 +0500 Subject: [PATCH] Refs #28024 -- Optimized LineString.__init__() by avoiding superfluous index and dimension checks. --- django/contrib/gis/geos/linestring.py | 10 ++++++---- 1 file 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.