From ac5c6695eb720060e9d46a30476c7e9e5471e41b Mon Sep 17 00:00:00 2001 From: Esteban Zimanyi Date: Sun, 21 Feb 2021 19:24:26 +0100 Subject: [PATCH] Optimize atGeometryfunction --- point/src/tpoint_spatialfuncs.c | 11 +++-------- .../expected/56_tpoint_spatialfuncs.test.out | 18 ++++++++++++++++++ .../queries/56_tpoint_spatialfuncs.test.sql | 3 +++ 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/point/src/tpoint_spatialfuncs.c b/point/src/tpoint_spatialfuncs.c index 3d7442c976..a93711a255 100644 --- a/point/src/tpoint_spatialfuncs.c +++ b/point/src/tpoint_spatialfuncs.c @@ -2760,14 +2760,9 @@ tgeompointseq_find_intersections(const TSequence *seq, int *count) double2_set(&result[k++], i, i - 1); else double2_set(&result[k++], i - 1, i - 2); - if (k % seq->count == 0) - { - /* Expand array of the result */ - double2 *tempresult = palloc0(sizeof(double2) * (k + seq->count)); - memcpy(tempresult, result, sizeof(double2) * k); - pfree(result); - result = tempresult; - } + /* We are sure that the number of stationary segments will always be + * less than the size of the result array (that is, seq->count) and thus + * we do need to test whether the result array should be expanded */ } else double3_set(&xranges[l++], Min(points[i-1].x, points[i].x), diff --git a/point/test/expected/56_tpoint_spatialfuncs.test.out b/point/test/expected/56_tpoint_spatialfuncs.test.out index 205f341615..786f66a810 100644 --- a/point/test/expected/56_tpoint_spatialfuncs.test.out +++ b/point/test/expected/56_tpoint_spatialfuncs.test.out @@ -1369,6 +1369,24 @@ SELECT isSimple(tgeompoint 'Interp=Stepwise;[Point(0 0)@2000-01-01, Point(1 1)@2 t (1 row) +SELECT isSimple(tgeompoint '[Point(0 0)@2000-01-01, Point(0 0)@2000-01-02, Point(1 1)@2000-01-03]'); + issimple +---------- + f +(1 row) + +SELECT isSimple(tgeompoint '[Point(0 0)@2000-01-01, Point(1 1)@2000-01-02, Point(1 1)@2000-01-03]'); + issimple +---------- + f +(1 row) + +SELECT isSimple(tgeompoint '[Point(0 0)@2000-01-01, Point(0 0)@2000-01-02, Point(1 1)@2000-01-03, Point(1 1)@2000-01-04]'); + issimple +---------- + f +(1 row) + SELECT isSimple(tgeompoint '{Point(0 0 0)@2000-01-01}'); issimple ---------- diff --git a/point/test/queries/56_tpoint_spatialfuncs.test.sql b/point/test/queries/56_tpoint_spatialfuncs.test.sql index 1924adc967..83c133a595 100644 --- a/point/test/queries/56_tpoint_spatialfuncs.test.sql +++ b/point/test/queries/56_tpoint_spatialfuncs.test.sql @@ -310,6 +310,9 @@ SELECT isSimple(tgeompoint '{Point(0 0)@2000-01-01, Point(1 1)@2000-01-02}'); SELECT isSimple(tgeompoint '{Point(0 0)@2000-01-01, Point(0 0)@2000-01-02}'); SELECT isSimple(tgeompoint 'Interp=Stepwise;[Point(0 0)@2000-01-01, Point(1 1)@2000-01-02, Point(1 1)@2000-01-03]'); SELECT isSimple(tgeompoint 'Interp=Stepwise;[Point(0 0)@2000-01-01, Point(1 1)@2000-01-02, Point(2 0)@2000-01-03]'); +SELECT isSimple(tgeompoint '[Point(0 0)@2000-01-01, Point(0 0)@2000-01-02, Point(1 1)@2000-01-03]'); +SELECT isSimple(tgeompoint '[Point(0 0)@2000-01-01, Point(1 1)@2000-01-02, Point(1 1)@2000-01-03]'); +SELECT isSimple(tgeompoint '[Point(0 0)@2000-01-01, Point(0 0)@2000-01-02, Point(1 1)@2000-01-03, Point(1 1)@2000-01-04]'); SELECT isSimple(tgeompoint '{Point(0 0 0)@2000-01-01}'); SELECT isSimple(tgeompoint '{Point(0 0 0)@2000-01-01, Point(1 1 1)@2000-01-02}');