Skip to content

Commit 1f2ac0b

Browse files
avoid creating std::string every time log_move_abort is called
1 parent 023ba47 commit 1f2ac0b

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

vpr/src/draw/manual_moves.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ void manual_move_cost_summary_dialog() {
212212
gtk_window_set_transient_for((GtkWindow*)dialog, (GtkWindow*)draw_state->manual_moves_state.manual_move_window);
213213

214214
//Create elements for the dialog and printing costs to the user.
215-
GtkWidget* title_label = gtk_label_new(NULL);
215+
GtkWidget* title_label = gtk_label_new(nullptr);
216216
gtk_label_set_markup((GtkLabel*)title_label, "<b>Move Costs and Outcomes</b>");
217217
std::string delta_cost = "Delta Cost: " + std::to_string(draw_state->manual_moves_state.manual_move_info.delta_cost) + " ";
218218
GtkWidget* delta_cost_label = gtk_label_new(delta_cost.c_str());

vpr/src/place/move_utils.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,15 @@
1616
bool f_placer_breakpoint_reached = false;
1717

1818
//Records counts of reasons for aborted moves
19-
static std::map<std::string, size_t> f_move_abort_reasons;
19+
static std::map<std::string, size_t, std::less<>> f_move_abort_reasons;
2020

21-
void log_move_abort(const std::string& reason) {
22-
++f_move_abort_reasons[reason];
21+
void log_move_abort(std::string_view reason) {
22+
auto it = f_move_abort_reasons.find(reason);
23+
if (it != f_move_abort_reasons.end()) {
24+
it->second++;
25+
} else {
26+
f_move_abort_reasons.emplace(reason, 1);
27+
}
2328
}
2429

2530
void report_aborted_moves() {

vpr/src/place/move_utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ struct t_range_limiters {
8686
};
8787

8888
//Records a reasons for an aborted move
89-
void log_move_abort(const std::string& reason);
89+
void log_move_abort(std::string_view reason);
9090

9191
//Prints a breif report about aborted move reasons and counts
9292
void report_aborted_moves();

0 commit comments

Comments
 (0)