From c1c9804db06e01efceef032347768e218d50f497 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sat, 23 May 2026 23:25:29 +0300 Subject: rpn: replace manual make+copy with slices.Clone in Stack.Values() Use slices.Clone() instead of the three-line make/copy idiom. This is more concise and correctly handles nil slices. --- internal/rpn/stack.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'internal') diff --git a/internal/rpn/stack.go b/internal/rpn/stack.go index f7b3ced..6032a37 100644 --- a/internal/rpn/stack.go +++ b/internal/rpn/stack.go @@ -3,7 +3,10 @@ package rpn -import "fmt" +import ( + "fmt" + "slices" +) // Stack represents an RPN stack of values. type Stack struct { @@ -50,9 +53,7 @@ func (s *Stack) Len() int { // Values returns a copy of all stack values (top-to-bottom order). func (s *Stack) Values() []StackValue { - vals := make([]StackValue, len(s.values)) - copy(vals, s.values) - return vals + return slices.Clone(s.values) } // Clear removes all values from the stack. -- cgit v1.2.3