coreutils icon indicating copy to clipboard operation
coreutils copied to clipboard

`expr`: optimization for integer values

Open tertsdiepraam opened this issue 2 years ago • 0 comments

Currently, expr uses only string values internally. This means that for an expression like 1 + 2 + 9 is evaluated as follows:

  1. Get the strings "1" and "2"
  2. Parse them into integers 1 and 2
  3. Add them to get 3
  4. Turn 3 into the string "3"
  5. Parse "3" back into the integer 3
  6. Parse "9" into 9
  7. Add them to get 12
  8. Turn 12 into 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.

tertsdiepraam avatar Nov 28 '23 08:11 tertsdiepraam