From d887209a86da6cfe5d3d34b638a34f769f15ac5f Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 24 May 2026 12:43:50 +0300 Subject: 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. --- internal/rpn/rpn_parse.go | 3 +-- 1 file changed, 1 insertion(+), 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 -- cgit v1.2.3