]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Reduce the number of calls to cellArea() in the ChooseLeaf() algorithm of
authordrh <>
Wed, 13 Sep 2023 12:06:02 +0000 (12:06 +0000)
committerdrh <>
Wed, 13 Sep 2023 12:06:02 +0000 (12:06 +0000)
rtree.

FossilOrigin-Name: c633fe6be0edc07a0aa1ac819d58b6c629b7c95b47b63516ae1b0a937f6a2b89

ext/rtree/rtree.c
manifest
manifest.uuid

index 0ce7fac4d4f451c2684b4cb03fe2e8cefe05898a..b2e8b3b65b7aba240965d3fb98ab128214fdbdcf 100644 (file)
@@ -2175,18 +2175,6 @@ static int cellContains(Rtree *pRtree, RtreeCell *p1, RtreeCell *p2){
   return 1;
 }
 
-/*
-** Return the amount cell p would grow by if it were unioned with pCell.
-*/
-static RtreeDValue cellGrowth(Rtree *pRtree, RtreeCell *p, RtreeCell *pCell){
-  RtreeDValue area;
-  RtreeCell cell;
-  memcpy(&cell, p, sizeof(RtreeCell));
-  area = cellArea(pRtree, &cell);
-  cellUnion(pRtree, &cell, pCell);
-  return (cellArea(pRtree, &cell)-area);
-}
-
 static RtreeDValue cellOverlap(
   Rtree *pRtree, 
   RtreeCell *p, 
@@ -2238,7 +2226,6 @@ static int ChooseLeaf(
     RtreeDValue fMinArea = RTREE_ZERO;
 
     int nCell = NCELL(pNode);
-    RtreeCell cell;
     RtreeNode *pChild = 0;
 
     /* Select the child node which will be enlarged the least if pCell
@@ -2246,16 +2233,17 @@ static int ChooseLeaf(
     ** the smallest area.
     */
     for(iCell=0; iCell<nCell; iCell++){
-      int bBest = 0;
+      RtreeCell cell;
       RtreeDValue growth;
       RtreeDValue area;
       nodeGetCell(pRtree, pNode, iCell, &cell);
-      growth = cellGrowth(pRtree, &cell, pCell);
       area = cellArea(pRtree, &cell);
-      if( iCell==0||growth<fMinGrowth||(growth==fMinGrowth && area<fMinArea) ){
-        bBest = 1;
-      }
-      if( bBest ){
+      cellUnion(pRtree, &cell, pCell);
+      growth = cellArea(pRtree, &cell)-area;
+      if( iCell==0
+       || growth<fMinGrowth
+       || (growth==fMinGrowth && area<fMinArea)
+      ){
         fMinGrowth = growth;
         fMinArea = area;
         iBest = cell.iRowid;
index 8e4f7efaefda22401bf0e8be2c9c6d3233f0db1b..e4853769458ddeb1ae0029f688232635e26afa1b 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Remove\sunused\svariable\sfrom\sthe\sChooseLeaf\salgorithm\sin\sr-tree.
-D 2023-09-13T11:36:44.782
+C Reduce\sthe\snumber\sof\scalls\sto\scellArea()\sin\sthe\sChooseLeaf()\salgorithm\sof\nrtree.
+D 2023-09-13T12:06:02.688
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -471,7 +471,7 @@ F ext/repair/test/checkindex01.test b530f141413b587c9eb78ff734de6bb79bc3515c3350
 F ext/repair/test/test.tcl 686d76d888dffd021f64260abf29a55c57b2cedfa7fc69150b42b1d6119aac3c
 F ext/rtree/README 6315c0d73ebf0ec40dedb5aa0e942bc8b54e3761
 F ext/rtree/geopoly.c 971e0b5bd9adaf0811feb8c0842a310811159da10319eb0e74fdb42bf26b99ca
-F ext/rtree/rtree.c e1410f3878d6c08c423dbe5f22dd8c63e80209548efe0a2b9480385349bff884
+F ext/rtree/rtree.c 2cf6c6a643bf7bd0eca116b37d81c65ad2407136ee523729050cb56da0e1651a
 F ext/rtree/rtree.h 4a690463901cb5e6127cf05eb8e642f127012fd5003830dbc974eca5802d9412
 F ext/rtree/rtree1.test 877d40b8b61b1f88cec9d4dc0ff8334f5b05299fac12a35141532e2881860e9d
 F ext/rtree/rtree2.test 9d9deddbb16fd0c30c36e6b4fdc3ee3132d765567f0f9432ee71e1303d32603d
@@ -2119,8 +2119,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 2170312c8d7f076cbb8319227de3fac981432dae186bc1928cd217e41119b580
-R 5a9318b9cac2f3018c96507d7d060a53
+P fb2e4a8067edc29ba64973820f265b21dfee0d32f4d675d32100d5eef93c2830
+R 50c424399f759c0884768065cbc409ef
 U drh
-Z 6f6864bbd34f25ad7f3ca334cafaebb1
+Z ac2eaf32235b1d74f19a79e1691a60ae
 # Remove this line to create a well-formed Fossil manifest.
index 92eac6d08c0fa7ec5ea1d0145a2d403999b7a258..7099b27f68a119d3a00f592c27aefc6432d1a332 100644 (file)
@@ -1 +1 @@
-fb2e4a8067edc29ba64973820f265b21dfee0d32f4d675d32100d5eef93c2830
\ No newline at end of file
+c633fe6be0edc07a0aa1ac819d58b6c629b7c95b47b63516ae1b0a937f6a2b89
\ No newline at end of file