Skip to content

Commit

Permalink
Add general optimizations
Browse files Browse the repository at this point in the history
Signed-off-by: Shrijit Singh <shrijitsingh99@gmail.com>
  • Loading branch information
shrijitsingh99 committed May 3, 2020
1 parent 06fa325 commit 2f2803d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ class InflationLayer : public Layer

void computeCaches();
void deleteKernels();
void inflate_area(int min_i, int min_j, int max_i, int max_j, unsigned char * master_grid);

unsigned int cellDistance(double world_dist)
{
Expand Down
21 changes: 9 additions & 12 deletions nav2_costmap_2d/plugins/inflation_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ InflationLayer::updateCosts(
int index = master_grid.getIndex(i, j);
unsigned char cost = master_array[index];
if (cost == LETHAL_OBSTACLE || (inflate_around_unknown_ && cost == NO_INFORMATION)) {
obs_bin.push_back(CellData(index, i, j, i, j));
obs_bin.emplace_back(index, i, j, i, j);
}
}
}
Expand All @@ -217,10 +217,8 @@ InflationLayer::updateCosts(
// can overtake previously inserted but farther away cells
std::map<double, std::vector<CellData>>::iterator bin;
for (bin = inflation_cells_.begin(); bin != inflation_cells_.end(); ++bin) {
for (unsigned int i = 0; i < bin->second.size(); ++i) {
for (auto & cell : bin->second) {
// process all cells at distance dist_bin.first
const CellData & cell = bin->second[i];

unsigned int index = cell.index_;

// ignore if already visited
Expand Down Expand Up @@ -291,7 +289,7 @@ InflationLayer::enqueue(
}

// push the cell data onto the inflation list and mark
inflation_cells_[distance].push_back(CellData(index, mx, my, src_x, src_y));
inflation_cells_[distance].emplace_back(CellData(index, mx, my, src_x, src_y));
}
}

Expand Down Expand Up @@ -330,26 +328,25 @@ InflationLayer::computeCaches()
void
InflationLayer::deleteKernels()
{
if (cached_distances_ != NULL) {
if (cached_distances_ != nullptr) {
for (unsigned int i = 0; i <= cached_cell_inflation_radius_ + 1; ++i) {
if (cached_distances_[i]) {
delete[] cached_distances_[i];
}
}
if (cached_distances_) {
delete[] cached_distances_;
}
cached_distances_ = NULL;
delete[] cached_distances_;

cached_distances_ = nullptr;
}

if (cached_costs_ != NULL) {
if (cached_costs_ != nullptr) {
for (unsigned int i = 0; i <= cached_cell_inflation_radius_ + 1; ++i) {
if (cached_costs_[i]) {
delete[] cached_costs_[i];
}
}
delete[] cached_costs_;
cached_costs_ = NULL;
cached_costs_ = nullptr;
}
}

Expand Down

0 comments on commit 2f2803d

Please sign in to comment.