Skip to content

Commit 0612ac4

Browse files
authored
perf: assorted performance changes (reubeno#936)
1 parent e05747c commit 0612ac4

4 files changed

Lines changed: 16 additions & 15 deletions

File tree

brush-core/src/commands.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -564,12 +564,16 @@ pub(crate) fn execute_external_command(
564564
args: &[CommandArg],
565565
) -> Result<ExecutionSpawnResult, error::Error> {
566566
// Filter out the args; we only want strings.
567-
let mut cmd_args = vec![];
568-
for arg in args {
569-
if let CommandArg::String(s) = arg {
570-
cmd_args.push(s);
571-
}
572-
}
567+
let cmd_args = args
568+
.iter()
569+
.filter_map(|e| {
570+
if let CommandArg::String(s) = e {
571+
Some(s)
572+
} else {
573+
None
574+
}
575+
})
576+
.collect::<Vec<_>>();
573577

574578
// Before we lose ownership of the open files, figure out if stdin will be a terminal.
575579
let child_stdin_is_terminal = context

brush-parser/benches/parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ mod unix {
1818
.unwrap()
1919
}
2020

21-
fn parse(tokens: &Vec<Token>) -> brush_parser::ast::Program {
21+
fn parse(tokens: &[Token]) -> brush_parser::ast::Program {
2222
parse_tokens(tokens, &brush_parser::ParserOptions::default()).unwrap()
2323
}
2424

brush-parser/src/parser/mod.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ impl<R: std::io::BufRead> Parser<R> {
184184
/// * `tokens` - The tokens to parse.
185185
/// * `options` - The options to use when parsing.
186186
pub fn parse_tokens(
187-
tokens: &Vec<Token>,
187+
tokens: &[Token],
188188
options: &ParserOptions,
189189
) -> Result<ast::Program, crate::error::ParseError> {
190190
let parse_result = peg::token_parser::program(&Tokens { tokens }, options);
@@ -193,7 +193,7 @@ pub fn parse_tokens(
193193

194194
fn parse_result_to_error<R>(
195195
parse_result: Result<R, ::peg::error::ParseError<usize>>,
196-
tokens: &Vec<Token>,
196+
tokens: &[Token],
197197
) -> Result<R, crate::error::ParseError>
198198
where
199199
R: std::fmt::Debug,
@@ -205,10 +205,7 @@ where
205205
}
206206
Err(parse_error) => {
207207
tracing::debug!(target: "parse", "Parse error: {:?}", parse_error);
208-
Err(crate::error::convert_peg_parse_error(
209-
&parse_error,
210-
tokens.as_slice(),
211-
))
208+
Err(crate::error::convert_peg_parse_error(&parse_error, tokens))
212209
}
213210
}
214211
}

brush-parser/src/prompt.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ mod tests {
168168
fn basic_prompt() -> Result<()> {
169169
assert_eq!(
170170
parse(r"\u@\h:\w$ ")?,
171-
vec![
171+
&[
172172
PromptPiece::CurrentUser,
173173
PromptPiece::Literal("@".to_owned()),
174174
PromptPiece::Hostname {
@@ -190,7 +190,7 @@ mod tests {
190190
fn brackets_and_vars() -> Result<()> {
191191
assert_eq!(
192192
parse(r"\[$foo\]\u > ")?,
193-
vec![
193+
&[
194194
PromptPiece::StartNonPrintingSequence,
195195
PromptPiece::Literal("$foo".to_owned()),
196196
PromptPiece::EndNonPrintingSequence,

0 commit comments

Comments
 (0)