From f5fff899921f6c6e07351ce5c0501cbbd3bb2e65 Mon Sep 17 00:00:00 2001 From: Katja Date: Fri, 7 Jun 2024 20:28:45 +0200 Subject: [PATCH] Reserving space in vector instead of resizing it. --- src/MultilevelAStarEx.cpp | 7 ++----- src/MultilevelAStarEx.h | 3 --- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/MultilevelAStarEx.cpp b/src/MultilevelAStarEx.cpp index 60e8bac..f0118c0 100644 --- a/src/MultilevelAStarEx.cpp +++ b/src/MultilevelAStarEx.cpp @@ -14,8 +14,6 @@ using std::vector; static const int STRAIGHT_DISTANCE = 10; static const int DIAGONAL_DISTANCE = 14; -Node::Node() { } - Node::Node(int x, int y) { this->hasUnit = false; @@ -153,14 +151,13 @@ void MultilevelAStarEx::init(const Rect2i ®ion) _height = region.get_size().height; _trans = region.get_position(); - _nodes.resize(_width * _height); + _nodes.reserve(_width * _height); - vector::iterator iter = _nodes.begin(); for (int y = 0; y < _height; y++) { for (int x = 0; x < _width; x++) { - *iter++ = Node(x, y); + _nodes.push_back(Node(x, y)); } } diff --git a/src/MultilevelAStarEx.h b/src/MultilevelAStarEx.h index bed0d39..3d12436 100644 --- a/src/MultilevelAStarEx.h +++ b/src/MultilevelAStarEx.h @@ -44,9 +44,6 @@ private: void close(int pass); NodeState state(int pass) const; int total_cost() const; - -public: - Node(); }; class MultilevelAStarEx : public godot::RefCounted