Jelajahi Sumber

Merge pull request #97843 from detomon/optimize-a-star-grid-2d-solve

Reduce allocations when solving path in `AStarGrid2D`
Thaddeus Crews 8 bulan lalu
induk
melakukan
3b1a481f13
1 mengubah file dengan 2 tambahan dan 1 penghapusan
  1. 2 1
      core/math/a_star_grid_2d.cpp

+ 2 - 1
core/math/a_star_grid_2d.cpp

@@ -503,6 +503,7 @@ bool AStarGrid2D::_solve(Point *p_begin_point, Point *p_end_point, bool p_allow_
 
 	LocalVector<Point *> open_list;
 	SortArray<Point *, SortPoints> sorter;
+	LocalVector<Point *> nbors;
 
 	p_begin_point->g_score = 0;
 	p_begin_point->f_score = _estimate_cost(p_begin_point->id, p_end_point->id);
@@ -528,7 +529,7 @@ bool AStarGrid2D::_solve(Point *p_begin_point, Point *p_end_point, bool p_allow_
 		open_list.remove_at(open_list.size() - 1);
 		p->closed_pass = pass; // Mark the point as closed.
 
-		LocalVector<Point *> nbors;
+		nbors.clear();
 		_get_nbors(p, nbors);
 
 		for (Point *e : nbors) {