mirror of
https://github.com/nushell/nushell.git
synced 2025-08-16 14:01:01 +02:00
Reuse existing small allocations if possible (#12335)
Those allocations are all small and insignificant in the grand scheme of things and the optimizer may be able to resolve some of those but better to be nice anyways. Primarily inspired by the new [`clippy::assigning_clones`](https://rust-lang.github.io/rust-clippy/master/index.html#/assigning_clones) - **Avoid reallocs with `clone_from` in `nu-parser`** - **Avoid realloc on assignment in `Stack`** - **Fix `clippy::assigning_clones` in `nu-cli`** - **Reuse allocations in `nu-explore` if possible**
This commit is contained in:
committed by
GitHub
parent
ce581a80a6
commit
cc39069e13
@ -104,7 +104,7 @@ impl ViewCommand for HelpCmd {
|
||||
}
|
||||
|
||||
fn parse(&mut self, args: &str) -> Result<()> {
|
||||
self.input_command = args.trim().to_owned();
|
||||
args.trim().clone_into(&mut self.input_command);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ impl ViewCommand for NuCmd {
|
||||
}
|
||||
|
||||
fn parse(&mut self, args: &str) -> Result<()> {
|
||||
self.command = args.trim().to_owned();
|
||||
args.trim().clone_into(&mut self.command);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ impl ViewCommand for TryCmd {
|
||||
}
|
||||
|
||||
fn parse(&mut self, args: &str) -> Result<()> {
|
||||
self.command = args.trim().to_owned();
|
||||
args.trim().clone_into(&mut self.command);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -295,7 +295,7 @@ fn render_ui(
|
||||
if pager.cmd_buf.run_cmd {
|
||||
let args = pager.cmd_buf.buf_cmd2.clone();
|
||||
pager.cmd_buf.run_cmd = false;
|
||||
pager.cmd_buf.buf_cmd2 = String::new();
|
||||
pager.cmd_buf.buf_cmd2.clear();
|
||||
|
||||
let out =
|
||||
pager_run_command(engine_state, stack, pager, &mut view_stack, &commands, args);
|
||||
@ -814,21 +814,21 @@ fn handle_general_key_events2<V>(
|
||||
{
|
||||
match key.code {
|
||||
KeyCode::Char('?') => {
|
||||
search.buf_cmd_input = String::new();
|
||||
search.buf_cmd_input.clear();
|
||||
search.is_search_input = true;
|
||||
search.is_reversed = true;
|
||||
|
||||
info.report = None;
|
||||
}
|
||||
KeyCode::Char('/') => {
|
||||
search.buf_cmd_input = String::new();
|
||||
search.buf_cmd_input.clear();
|
||||
search.is_search_input = true;
|
||||
search.is_reversed = false;
|
||||
|
||||
info.report = None;
|
||||
}
|
||||
KeyCode::Char(':') => {
|
||||
command.buf_cmd2 = String::new();
|
||||
command.buf_cmd2.clear();
|
||||
command.is_cmd_input = true;
|
||||
command.cmd_exec_info = None;
|
||||
|
||||
@ -837,7 +837,7 @@ fn handle_general_key_events2<V>(
|
||||
KeyCode::Char('n') => {
|
||||
if !search.search_results.is_empty() {
|
||||
if search.buf_cmd_input.is_empty() {
|
||||
search.buf_cmd_input = search.buf_cmd.clone();
|
||||
search.buf_cmd_input.clone_from(&search.buf_cmd);
|
||||
}
|
||||
|
||||
if search.search_index + 1 == search.search_results.len() {
|
||||
@ -863,7 +863,7 @@ fn search_input_key_event(
|
||||
) -> bool {
|
||||
match &key.code {
|
||||
KeyCode::Esc => {
|
||||
buf.buf_cmd_input = String::new();
|
||||
buf.buf_cmd_input.clear();
|
||||
|
||||
if let Some(view) = view {
|
||||
if !buf.buf_cmd.is_empty() {
|
||||
@ -878,7 +878,7 @@ fn search_input_key_event(
|
||||
true
|
||||
}
|
||||
KeyCode::Enter => {
|
||||
buf.buf_cmd = buf.buf_cmd_input.clone();
|
||||
buf.buf_cmd.clone_from(&buf.buf_cmd_input);
|
||||
buf.is_search_input = false;
|
||||
|
||||
true
|
||||
@ -982,7 +982,8 @@ fn cmd_input_key_event(buf: &mut CommandBuf, key: &KeyEvent) -> bool {
|
||||
buf.cmd_history_pos + 1,
|
||||
buf.cmd_history.len().saturating_sub(1),
|
||||
);
|
||||
buf.buf_cmd2 = buf.cmd_history[buf.cmd_history_pos].clone();
|
||||
buf.buf_cmd2
|
||||
.clone_from(&buf.cmd_history[buf.cmd_history_pos]);
|
||||
}
|
||||
|
||||
true
|
||||
@ -991,7 +992,8 @@ fn cmd_input_key_event(buf: &mut CommandBuf, key: &KeyEvent) -> bool {
|
||||
if !buf.cmd_history.is_empty() {
|
||||
buf.cmd_history_allow = true;
|
||||
buf.cmd_history_pos = buf.cmd_history_pos.saturating_sub(1);
|
||||
buf.buf_cmd2 = buf.cmd_history[buf.cmd_history_pos].clone();
|
||||
buf.buf_cmd2
|
||||
.clone_from(&buf.cmd_history[buf.cmd_history_pos]);
|
||||
}
|
||||
|
||||
true
|
||||
|
@ -812,7 +812,7 @@ fn _transpose_table(
|
||||
let mut data = vec![vec![Value::default(); count_rows]; count_columns];
|
||||
for (row, values) in values.iter().enumerate() {
|
||||
for (column, value) in values.iter().enumerate() {
|
||||
data[column][row] = value.to_owned();
|
||||
data[column][row].clone_from(value);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user