Perform builtin lookup when parsing
Created by: AgustinCB
I wasn't able to find how to run the benchmarks, if you give me instructions, I'll be happy to include them in the pr.
Problem: Perform lookup of builtin when parsing and not when executing, to improve for loops.
Solution: Perform the same logic to detect if a command is a builtin or not when creating a job and store in the struct an option for the pointer of the function of the builtin. On execution, check if that option is set to something instead of looking for the builtin.
Changes introduced by this pull request:
- Add a type alias for the builtin function,
BuiltinFunction
. - Add a new member to the job struct of type
Option<BuiltinFunction>
and namebuiltin
. - Make custom Implementations of the traits
PartialEq
andDebug
for the job struct, since function pointer don't have one. - On job creation, determine if the command is a builtin and set the
builtin
value accordingly. - On job execution, use that struct member to determine whether a job is a builtin or not.
TODOs: Is there any other fn(&[&str], &mut Shell) -> i32
that we can change to BuiltinFunction
?
Fixes: Expensive lookups on for loops.
State: Ready for review.
Blocking/related: #569 (closed)