mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-12 13:08:49 +00:00
Fix a todo!
Stop cloning the delimiter unnecessarily in builtin read.
This commit is contained in:
parent
36d7049749
commit
a14906f52f
1 changed files with 13 additions and 13 deletions
|
@ -686,15 +686,15 @@ pub fn read(parser: &Parser, streams: &mut IoStreams, argv: &mut [&wstr]) -> Opt
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo!("don't clone")
|
let mut ifs_delimiter = WString::new();
|
||||||
let delimiter = opts
|
let delimiter: &wstr = opts.delimiter.as_deref().unwrap_or_else(|| {
|
||||||
.delimiter
|
ifs_delimiter = parser
|
||||||
.clone()
|
.vars()
|
||||||
.or_else(|| {
|
.get_unless_empty(L!("IFS"))
|
||||||
let ifs = parser.vars().get_unless_empty(L!("IFS"));
|
.map(|var| var.as_string())
|
||||||
ifs.map(|ifs| ifs.as_string())
|
|
||||||
})
|
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
&ifs_delimiter
|
||||||
|
});
|
||||||
|
|
||||||
if delimiter.is_empty() {
|
if delimiter.is_empty() {
|
||||||
// Every character is a separate token with one wrinkle involving non-array mode where
|
// Every character is a separate token with one wrinkle involving non-array mode where
|
||||||
|
@ -735,7 +735,7 @@ pub fn read(parser: &Parser, streams: &mut IoStreams, argv: &mut [&wstr]) -> Opt
|
||||||
if opts.delimiter.is_none() {
|
if opts.delimiter.is_none() {
|
||||||
// We're using IFS, so tokenize the buffer using each IFS char. This is for backward
|
// We're using IFS, so tokenize the buffer using each IFS char. This is for backward
|
||||||
// compatibility with old versions of fish.
|
// compatibility with old versions of fish.
|
||||||
let tokens = split_string_tok(&buff, &delimiter, None)
|
let tokens = split_string_tok(&buff, delimiter, None)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|s| s.to_owned())
|
.map(|s| s.to_owned())
|
||||||
.collect();
|
.collect();
|
||||||
|
@ -743,7 +743,7 @@ pub fn read(parser: &Parser, streams: &mut IoStreams, argv: &mut [&wstr]) -> Opt
|
||||||
var_ptr += 1;
|
var_ptr += 1;
|
||||||
} else {
|
} else {
|
||||||
// We're using a delimiter provided by the user so use the `string split` behavior.
|
// We're using a delimiter provided by the user so use the `string split` behavior.
|
||||||
let splits = split_about(&buff, &delimiter, usize::MAX, false)
|
let splits = split_about(&buff, delimiter, usize::MAX, false)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|s| s.to_owned())
|
.map(|s| s.to_owned())
|
||||||
.collect();
|
.collect();
|
||||||
|
@ -757,7 +757,7 @@ pub fn read(parser: &Parser, streams: &mut IoStreams, argv: &mut [&wstr]) -> Opt
|
||||||
// compatibility with old versions of fish.
|
// compatibility with old versions of fish.
|
||||||
// Note the final variable gets any remaining text.
|
// Note the final variable gets any remaining text.
|
||||||
let mut var_vals: Vec<WString> =
|
let mut var_vals: Vec<WString> =
|
||||||
split_string_tok(&buff, &delimiter, Some(vars_left(var_ptr)))
|
split_string_tok(&buff, delimiter, Some(vars_left(var_ptr)))
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|s| s.to_owned())
|
.map(|s| s.to_owned())
|
||||||
.collect();
|
.collect();
|
||||||
|
@ -775,7 +775,7 @@ pub fn read(parser: &Parser, streams: &mut IoStreams, argv: &mut [&wstr]) -> Opt
|
||||||
// We're using a delimiter provided by the user so use the `string split` behavior.
|
// We're using a delimiter provided by the user so use the `string split` behavior.
|
||||||
// We're making at most argc - 1 splits so the last variable
|
// We're making at most argc - 1 splits so the last variable
|
||||||
// is set to the remaining string.
|
// is set to the remaining string.
|
||||||
let splits = split_about(&buff, &delimiter, argc - 1, false);
|
let splits = split_about(&buff, delimiter, argc - 1, false);
|
||||||
assert!(splits.len() <= vars_left(var_ptr));
|
assert!(splits.len() <= vars_left(var_ptr));
|
||||||
for split in splits {
|
for split in splits {
|
||||||
parser.set_var_and_fire(argv[var_ptr], opts.place, vec![split.to_owned()]);
|
parser.set_var_and_fire(argv[var_ptr], opts.place, vec![split.to_owned()]);
|
||||||
|
|
Loading…
Reference in a new issue