Skip to content

Commit

Permalink
simplify to use slices.Reverse
Browse files Browse the repository at this point in the history
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
  • Loading branch information
tonistiigi committed Jun 13, 2024
1 parent 70be02f commit ecb058d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
5 changes: 2 additions & 3 deletions cache/remotecache/inline/inline.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package inline
import (
"context"
"encoding/json"
"slices"

"github.com/containerd/containerd/labels"
"github.com/moby/buildkit/cache/remotecache"
Expand Down Expand Up @@ -167,8 +168,6 @@ func layerToBlobs(idx int, layers []v1.CacheLayer) []digest.Digest {
idx = layer.ParentIndex
}
// reverse so they go lowest to highest
for i, j := 0, len(ds)-1; i < j; i, j = i+1, j-1 {
ds[i], ds[j] = ds[j], ds[i]
}
slices.Reverse(ds)
return ds
}
7 changes: 2 additions & 5 deletions frontend/dockerfile/shell/lex.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"fmt"
"regexp"
"slices"
"strings"
"text/scanner"
"unicode"
Expand Down Expand Up @@ -646,11 +647,7 @@ func reversePattern(pattern string) string {

func reverseString(str string) string {
out := []rune(str)
outIdx := len(out) - 1
for i := 0; i < outIdx; i++ {
out[i], out[outIdx] = out[outIdx], out[i]
outIdx--
}
slices.Reverse(out)
return string(out)
}

Expand Down

0 comments on commit ecb058d

Please sign in to comment.