Browse Source

UI: Optimize undo/redo functions with constant references

Richard Stanway 3 years ago
parent
commit
3ce12bc5e9
2 changed files with 9 additions and 8 deletions
  1. 6 5
      UI/undo-stack-obs.cpp
  2. 3 3
      UI/undo-stack-obs.hpp

+ 6 - 5
UI/undo-stack-obs.cpp

@@ -30,9 +30,10 @@ void undo_stack::clear()
 	ui->actionMainRedo->setDisabled(true);
 }
 
-void undo_stack::add_action(const QString &name, undo_redo_cb undo,
-			    undo_redo_cb redo, std::string undo_data,
-			    std::string redo_data, bool repeatable)
+void undo_stack::add_action(const QString &name, const undo_redo_cb &undo,
+			    const undo_redo_cb &redo,
+			    const std::string &undo_data,
+			    const std::string &redo_data, bool repeatable)
 {
 	if (!is_enabled())
 		return;
@@ -42,8 +43,6 @@ void undo_stack::add_action(const QString &name, undo_redo_cb undo,
 		undo_items.pop_back();
 	}
 
-	undo_redo_t n = {name, undo_data, redo_data, undo, redo};
-
 	if (repeatable) {
 		repeat_reset_timer.start();
 	}
@@ -54,6 +53,8 @@ void undo_stack::add_action(const QString &name, undo_redo_cb undo,
 		return;
 	}
 
+	undo_redo_t n = {name, undo_data, redo_data, undo, redo};
+
 	last_is_repeatable = repeatable;
 	undo_items.push_front(n);
 	clear_redo();

+ 3 - 3
UI/undo-stack-obs.hpp

@@ -53,9 +53,9 @@ public:
 	void pop_disabled();
 
 	void clear();
-	void add_action(const QString &name, undo_redo_cb undo,
-			undo_redo_cb redo, std::string undo_data,
-			std::string redo_data, bool repeatable = false);
+	void add_action(const QString &name, const undo_redo_cb &undo,
+			const undo_redo_cb &redo, const std::string &undo_data,
+			const std::string &redo_data, bool repeatable = false);
 	void undo();
 	void redo();
 };