coreutils
coreutils copied to clipboard
`expr`: optimization for integer values
Currently, expr uses only string values internally. This means that for an expression like 1 + 2 + 9 is evaluated as follows:
- Get the strings
"1"and"2" - Parse them into integers
1and2 - Add them to get
3 - Turn
3into the string"3" - Parse
"3"back into the integer3 - Parse
"9"into9 - Add them to get
12 - Turn
12into the string"12"
That's a lot of parsing and stringifying. Instead we could have an enum that can contain either an integer or a string which can be turned into the desired value.