diff options
| author | Paul Buetow <paul@buetow.org> | 2026-05-24 12:43:50 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-05-24 12:43:50 +0300 |
| commit | d887209a86da6cfe5d3d34b638a34f769f15ac5f (patch) | |
| tree | f102f079986f3ee8c37e4cc7342bdfd3adf2b3d4 | |
| parent | 4935b8adab236e76220d2f2e06cf72857af834fa (diff) | |
rpn: eliminate duplicate ParseFloat in pushLiteral
pushLiteral called strconv.ParseFloat twice for non-RationalMode
input: once to check if token is a number, once to get the value.
Capture the parsed value from the first call to avoid redundant
parsing.
| -rw-r--r-- | internal/rpn/rpn_parse.go | 3 |
1 files changed, 1 insertions, 2 deletions
diff --git a/internal/rpn/rpn_parse.go b/internal/rpn/rpn_parse.go index 40e1d4e..9c31324 100644 --- a/internal/rpn/rpn_parse.go +++ b/internal/rpn/rpn_parse.go @@ -492,7 +492,7 @@ func (r *RPN) pushLiteral(stack *Stack, token string) (bool, error) { } // Check if it's a number - if _, err := strconv.ParseFloat(token, 64); err == nil { + if num, err := strconv.ParseFloat(token, 64); err == nil { if stack.Len() >= r.maxStack { return false, fmt.Errorf("stack overflow") } @@ -503,7 +503,6 @@ func (r *RPN) pushLiteral(stack *Stack, token string) (bool, error) { } stack.Push(rat) } else { - num, _ := strconv.ParseFloat(token, 64) stack.Push(NewFloat(num)) } return true, nil |
