Pass some parameters by reference/move

This commit is contained in:
Johannes Altmanninger 2021-03-21 16:06:14 +01:00
parent 516a70d9cb
commit 508044bce1
4 changed files with 8 additions and 7 deletions

View File

@ -238,7 +238,7 @@ struct history_impl_t {
// item_at_index until a call to resolve_pending(). Pending items are tracked with an offset // item_at_index until a call to resolve_pending(). Pending items are tracked with an offset
// into the array of new items, so adding a non-pending item has the effect of resolving all // into the array of new items, so adding a non-pending item has the effect of resolving all
// pending items. // pending items.
void add(history_item_t item, bool pending = false, bool do_save = true); void add(history_item_t &&item, bool pending = false, bool do_save = true);
// Internal function. // Internal function.
void clear_file_state(); void clear_file_state();
@ -379,7 +379,7 @@ struct history_impl_t {
size_t size(); size_t size();
}; };
void history_impl_t::add(history_item_t item, bool pending, bool do_save) { void history_impl_t::add(history_item_t &&item, bool pending, bool do_save) {
assert(item.timestamp() != 0 && "Should not add an item with a 0 timestamp"); assert(item.timestamp() != 0 && "Should not add an item with a 0 timestamp");
// We use empty items as sentinels to indicate the end of history. // We use empty items as sentinels to indicate the end of history.
// Do not allow them to be added (#6032). // Do not allow them to be added (#6032).
@ -1327,7 +1327,7 @@ bool history_t::is_default() const { return impl()->is_default(); }
bool history_t::is_empty() { return impl()->is_empty(); } bool history_t::is_empty() { return impl()->is_empty(); }
void history_t::add(history_item_t item, bool pending) { impl()->add(std::move(item), pending); } void history_t::add(history_item_t &&item, bool pending) { impl()->add(std::move(item), pending); }
void history_t::remove(const wcstring &str) { impl()->remove(str); } void history_t::remove(const wcstring &str) { impl()->remove(str); }

View File

@ -146,7 +146,7 @@ class history_t {
// Privately add an item. If pending, the item will not be returned by history searches until a // Privately add an item. If pending, the item will not be returned by history searches until a
// call to resolve_pending. Any trailing ephemeral items are dropped. // call to resolve_pending. Any trailing ephemeral items are dropped.
void add(history_item_t item, bool pending = false); void add(history_item_t &&item, bool pending = false);
// Add a new history item with text \p str to the end of history. // Add a new history item with text \p str to the end of history.
void add(wcstring str); void add(wcstring str);

View File

@ -71,7 +71,7 @@ timer_snapshot_t timer_snapshot_t::take() {
return snapshot; return snapshot;
} }
wcstring timer_snapshot_t::print_delta(timer_snapshot_t t1, timer_snapshot_t t2, wcstring timer_snapshot_t::print_delta(const timer_snapshot_t &t1, const timer_snapshot_t &t2,
bool verbose /* = true */) { bool verbose /* = true */) {
int64_t fish_sys_micros = micros(t2.cpu_fish.ru_stime) - micros(t1.cpu_fish.ru_stime); int64_t fish_sys_micros = micros(t2.cpu_fish.ru_stime) - micros(t1.cpu_fish.ru_stime);
int64_t fish_usr_micros = micros(t2.cpu_fish.ru_utime) - micros(t1.cpu_fish.ru_utime); int64_t fish_usr_micros = micros(t2.cpu_fish.ru_utime) - micros(t1.cpu_fish.ru_utime);

View File

@ -22,7 +22,8 @@ struct timer_snapshot_t {
std::chrono::time_point<std::chrono::steady_clock> wall; std::chrono::time_point<std::chrono::steady_clock> wall;
static timer_snapshot_t take(); static timer_snapshot_t take();
static wcstring print_delta(timer_snapshot_t t1, timer_snapshot_t t2, bool verbose = false); static wcstring print_delta(const timer_snapshot_t &t1, const timer_snapshot_t &t2,
bool verbose = false);
private: private:
timer_snapshot_t() {} timer_snapshot_t() {}