diff options
| author | Paul Buetow <paul@buetow.org> | 2026-05-23 23:25:29 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-05-23 23:25:29 +0300 |
| commit | c1c9804db06e01efceef032347768e218d50f497 (patch) | |
| tree | 2bbe935e29e4c7d8c0e89200d908b7e631a6a48d /internal | |
| parent | 713e81daef9b01f24c4120c5e3e34d242f226797 (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.go | 9 |
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. |
