From d3247bbc543b4b7ce25b5e713861b413f0cc3fb7 Mon Sep 17 00:00:00 2001 From: Bensuperpc Date: Fri, 21 Jun 2024 21:51:56 +0200 Subject: [PATCH] Improve perf with static lambda function Signed-off-by: Bensuperpc --- README.md | 2 +- include/astar/astar.hpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 02726cb..0a9a952 100755 --- a/README.md +++ b/README.md @@ -196,7 +196,7 @@ Sources and references that I have used to make this library. * [a-star](https://www.ce.unipr.it/people/medici/a-star.html)$ * [A* Search Algorithm](https://yuminlee2.medium.com/a-search-algorithm-42c1a13fcf9f) -## Bench others astar implementations +## Others astar implementations The list of others astar implementations that I have benchmarked to compare the performance of my implementation. diff --git a/include/astar/astar.hpp b/include/astar/astar.hpp index b4ba127..d6a1f76 100644 --- a/include/astar/astar.hpp +++ b/include/astar/astar.hpp @@ -171,7 +171,7 @@ class AStar final : public AStarVirtual { Node* currentNode = nullptr; - auto compareFn = [](const Node* a, const Node* b) { return a->getTotalCost() > b->getTotalCost(); }; + static auto compareFn = [](const Node* a, const Node* b) { return a->getTotalCost() > b->getTotalCost(); }; std::priority_queue*, std::vector*>, decltype(compareFn)> openNodeVecPQueue = std::priority_queue*, std::vector*>, decltype(compareFn)>(compareFn); @@ -278,7 +278,7 @@ class AStarFast final : public AStarVirtual { Node* currentNode = nullptr; - auto compareFn = [](const Node* a, const Node* b) { return a->getTotalCost() > b->getTotalCost(); }; + static auto compareFn = [](const Node* a, const Node* b) { return a->getTotalCost() > b->getTotalCost(); }; std::priority_queue*, std::vector*>, decltype(compareFn)> openNodeVecPQueue = std::priority_queue*, std::vector*>, decltype(compareFn)>(compareFn); std::unordered_map*, Vec2i::hash> openNodeMap;