Skip to content

Commit

Permalink
perf: use vector::reserve to speedup squares_closer_to
Browse files Browse the repository at this point in the history
ports CleverRaven/Cataclysm-DDA#45424

Co-authored-by: Aivean <aiveeen@gmail.com>
  • Loading branch information
scarf005 and Aivean committed Aug 22, 2023
1 parent 9035e70 commit cffe99c
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/line.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,7 @@ std::string direction_suffix( const tripoint &p, const tripoint &q )
std::vector<tripoint> squares_closer_to( const tripoint &from, const tripoint &to )
{
std::vector<tripoint> adjacent_closer_squares;
adjacent_closer_squares.reserve( 5 );
const tripoint d( -from + to );
const point a( std::abs( d.x ), std::abs( d.y ) );
if( d.z != 0 ) {
Expand Down Expand Up @@ -591,6 +592,7 @@ std::vector<point> squares_in_direction( point p1, point p2 )
int junk = 0;
point center_square = line_to( p1, p2, junk )[0];
std::vector<point> adjacent_squares;
adjacent_squares.reserve( 3 );
adjacent_squares.push_back( center_square );
if( p1.x == center_square.x ) {
// Horizontally adjacent.
Expand Down

0 comments on commit cffe99c

Please sign in to comment.