mirror of
https://github.com/helix-editor/helix.git
synced 2024-12-04 15:23:30 +04:00
Remove unnecessary Vec collections for Registers::write callsites
These callsites either used `vec![..]` instead of a static slice `[..]` or, worse, collected into a Vec unnecessarily. The refactor in the parent commit to `IntoIterator<Item = String>` for `Registers::write` makes these Vecs unnecessary as the values are appended to each register via `VecDeque::extend`. We could take this change further by returning the number of values we yanked in `Registers::write`. However this would only remove the need to collect from one callsite, so this further refactor is deferred until it would more useful in the future.
This commit is contained in:
parent
f466212beb
commit
7cbdff4df8
@ -2644,7 +2644,7 @@ fn delete_selection_impl(cx: &mut Context, op: Operation, yank: YankAction) {
|
||||
if cx.register != Some('_') && matches!(yank, YankAction::Yank) {
|
||||
// yank the selection
|
||||
let text = doc.text().slice(..);
|
||||
let values: Vec<String> = selection.fragments(text).map(Cow::into_owned).collect();
|
||||
let values = selection.fragments(text).map(Cow::into_owned);
|
||||
let reg_name = cx.register.unwrap_or('"');
|
||||
if let Err(err) = cx.editor.registers.write(reg_name, values) {
|
||||
cx.editor.set_error(err.to_string());
|
||||
@ -4137,7 +4137,7 @@ fn yank_joined_impl(editor: &mut Editor, separator: &str, register: char) {
|
||||
acc
|
||||
});
|
||||
|
||||
match editor.registers.write(register, vec![joined]) {
|
||||
match editor.registers.write(register, [joined]) {
|
||||
Ok(_) => editor.set_status(format!(
|
||||
"joined and yanked {selections} selection{} to register {register}",
|
||||
if selections == 1 { "" } else { "s" }
|
||||
@ -4170,7 +4170,7 @@ fn yank_primary_selection_impl(editor: &mut Editor, register: char) {
|
||||
|
||||
let selection = doc.selection(view.id).primary().fragment(text).to_string();
|
||||
|
||||
match editor.registers.write(register, vec![selection]) {
|
||||
match editor.registers.write(register, [selection]) {
|
||||
Ok(_) => editor.set_status(format!("yanked primary selection to register {register}",)),
|
||||
Err(err) => editor.set_error(err.to_string()),
|
||||
}
|
||||
@ -5932,18 +5932,15 @@ fn record_macro(cx: &mut Context) {
|
||||
if let Some((reg, mut keys)) = cx.editor.macro_recording.take() {
|
||||
// Remove the keypress which ends the recording
|
||||
keys.pop();
|
||||
let s = keys
|
||||
.into_iter()
|
||||
.map(|key| {
|
||||
let s = key.to_string();
|
||||
if s.chars().count() == 1 {
|
||||
s
|
||||
} else {
|
||||
format!("<{}>", s)
|
||||
}
|
||||
})
|
||||
.collect::<String>();
|
||||
match cx.editor.registers.write(reg, vec![s]) {
|
||||
let s = keys.into_iter().map(|key| {
|
||||
let s = key.to_string();
|
||||
if s.chars().count() == 1 {
|
||||
s
|
||||
} else {
|
||||
format!("<{}>", s)
|
||||
}
|
||||
});
|
||||
match cx.editor.registers.write(reg, s) {
|
||||
Ok(_) => cx
|
||||
.editor
|
||||
.set_status(format!("Recorded to register [{}]", reg)),
|
||||
|
Loading…
Reference in New Issue
Block a user