summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-05-23 23:25:29 +0300
committerPaul Buetow <paul@buetow.org>2026-05-23 23:25:29 +0300
commitc1c9804db06e01efceef032347768e218d50f497 (patch)
tree2bbe935e29e4c7d8c0e89200d908b7e631a6a48d /internal
parent713e81daef9b01f24c4120c5e3e34d242f226797 (diff)
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.
Diffstat (limited to 'internal')
-rw-r--r--internal/rpn/stack.go9
1 files changed, 5 insertions, 4 deletions
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.