Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions cmd/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"encoding/json"
"errors"
"fmt"
"maps"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -1187,9 +1188,7 @@ a contains 4 if {
if bundleType.tar {
files["bundle.tar.gz"] = ""
} else {
for k, v := range tc.modules {
files[k] = v
}
maps.Copy(files, tc.modules)

manifest := bundle.Manifest{
RegoVersion: &tc.bundleRegoVersion,
Expand Down
9 changes: 2 additions & 7 deletions cmd/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"path"
"path/filepath"
"reflect"
"slices"
"strconv"
"strings"
"testing"
Expand Down Expand Up @@ -1404,13 +1405,7 @@ func capsWithoutFeat(regoVersion ast.RegoVersion, feat ...string) *ast.Capabilit

feats := make([]string, 0, len(caps.Features))
for _, f := range caps.Features {
skip := false
for _, skipF := range feat {
if f == skipF {
skip = true
break
}
}
skip := slices.Contains(feat, f)
if !skip {
feats = append(feats, f)
}
Expand Down
5 changes: 2 additions & 3 deletions cmd/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"io"
"io/fs"
"maps"
"os"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -94,9 +95,7 @@ func checkModules(params checkParams, args []string) error {
if err != nil {
return err
}
for name, mod := range b.ParsedModules(path) {
modules[name] = mod
}
maps.Copy(modules, b.ParsedModules(path))
}
} else {
f := loaderFilter{
Expand Down
5 changes: 2 additions & 3 deletions cmd/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package cmd
import (
"encoding/json"
"fmt"
"maps"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -1262,9 +1263,7 @@ q contains x if {
if bundleType.tar {
files["bundle.tar.gz"] = ""
} else {
for k, v := range tc.files {
files[k] = v
}
maps.Copy(files, tc.files)
}

test.WithTempFS(files, func(root string) {
Expand Down
5 changes: 2 additions & 3 deletions cmd/deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"errors"
"fmt"
"io"
"maps"
"os"

"github.com/open-policy-agent/opa/internal/presentation"
Expand Down Expand Up @@ -147,9 +148,7 @@ func deps(args []string, params depsCommandParams, w io.Writer) error {
return err
}

for name, mod := range b.ParsedModules(path) {
modules[name] = mod
}
maps.Copy(modules, b.ParsedModules(path))
}
}

Expand Down
5 changes: 2 additions & 3 deletions cmd/deps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package cmd
import (
"fmt"
"io"
"maps"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -519,9 +520,7 @@ p contains 4 if {
if bundleType.tar {
files["bundle.tar.gz"] = ""
} else {
for k, v := range tc.files {
files[k] = v
}
maps.Copy(files, tc.files)
}

test.WithTempFS(files, func(root string) {
Expand Down
4 changes: 1 addition & 3 deletions cmd/eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3476,9 +3476,7 @@ p contains 2 if {
if bundleType.tar {
files["bundle.tar.gz"] = ""
} else {
for k, v := range tc.files {
files[k] = v
}
maps.Copy(files, tc.files)
}

test.WithTempFS(files, func(root string) {
Expand Down
5 changes: 2 additions & 3 deletions cmd/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/json"
"errors"
"fmt"
"maps"
"os"
"path/filepath"
"regexp"
Expand Down Expand Up @@ -854,9 +855,7 @@ main contains "hello" if {
if bundleType.tar {
files["bundle.tar.gz"] = ""
} else {
for k, v := range tc.files {
files[k] = v
}
maps.Copy(files, tc.files)
}

test.WithTempFS(files, func(root string) {
Expand Down
5 changes: 2 additions & 3 deletions cmd/inspect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package cmd
import (
"bytes"
"fmt"
"maps"
"os"
"path/filepath"
"reflect"
Expand Down Expand Up @@ -956,9 +957,7 @@ p contains 2 if {
if bundleType.tar {
files["bundle.tar.gz"] = ""
} else {
for k, v := range tc.files {
files[k] = v
}
maps.Copy(files, tc.files)
}

test.WithTempFS(files, func(root string) {
Expand Down
7 changes: 3 additions & 4 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"fmt"
"os"
"path"
"slices"
"time"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -417,10 +418,8 @@ func verifyCipherSuites(cipherSuites []string) (*[]uint16, error) {
}

// verify no TLS 1.3 cipher suites as they are not configurable
for _, ver := range val.SupportedVersions {
if ver == tls.VersionTLS13 {
return nil, fmt.Errorf("TLS 1.3 cipher suite \"%v\" is not configurable", c)
}
if slices.Contains(val.SupportedVersions, tls.VersionTLS13) {
return nil, fmt.Errorf("TLS 1.3 cipher suite \"%v\" is not configurable", c)
}

cipherSuitesIDs = append(cipherSuitesIDs, val.ID)
Expand Down
5 changes: 2 additions & 3 deletions cmd/test_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"fmt"
"io"
"maps"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -3482,9 +3483,7 @@ test_l if {
if bundleType.tar {
files["bundle.tar.gz"] = ""
} else {
for k, v := range tc.files {
files[k] = v
}
maps.Copy(files, tc.files)
}

test.WithTempFS(files, func(root string) {
Expand Down
4 changes: 1 addition & 3 deletions compile/compile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,7 @@ p contains "B" if {
if bundleType.tar {
files["bundle.tar"] = ""
} else {
for k, v := range tc.files {
files[k] = v
}
maps.Copy(files, tc.files)
}

test.WithTestFS(tc.files, false, func(root string, fsys fs.FS) {
Expand Down
2 changes: 1 addition & 1 deletion internal/edittree/bitvector/bitvector.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func shiftLower(bit byte, b []byte) byte {
// position of the first byte in the slice.
// This returns the bit that was shifted off the last byte.
func shiftHigher(bit byte, b []byte) byte {
for i := 0; i < len(b); i++ {
for i := range b {
newByte := b[i] << 1
newByte |= bit
bit = (b[i] & 0x80) >> 7
Expand Down
9 changes: 2 additions & 7 deletions internal/gojsonschema/schemaType.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ package gojsonschema
import (
"errors"
"fmt"
"slices"
"strings"
)

Expand Down Expand Up @@ -58,13 +59,7 @@ func (t *jsonSchemaType) Add(etype string) error {

func (t *jsonSchemaType) Contains(etype string) bool {

for _, v := range t.types {
if v == etype {
return true
}
}

return false
return slices.Contains(t.types, etype)
}

func (t *jsonSchemaType) String() string {
Expand Down
8 changes: 2 additions & 6 deletions internal/gojsonschema/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,11 @@ package gojsonschema
import (
"encoding/json"
"math/big"
"slices"
)

func isStringInSlice(s []string, what string) bool {
for i := range s {
if s[i] == what {
return true
}
}
return false
return slices.Contains(s, what)
}

func marshalToJSONString(value any) (*string, error) {
Expand Down
5 changes: 1 addition & 4 deletions internal/presentation/presentation.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ func (o DepAnalysisOutput) Pretty(w io.Writer) error {

// Fill two columns if results have base and virtual docs. Else fill one column.
if len(o.Base) > 0 && len(o.Virtual) > 0 {
maxLen := len(o.Base)
if len(o.Virtual) > maxLen {
maxLen = len(o.Virtual)
}
maxLen := max(len(o.Virtual), len(o.Base))
headers = []string{"Base Documents", "Virtual Documents"}
rows = make([][]string, maxLen)
for i := range rows {
Expand Down
2 changes: 1 addition & 1 deletion internal/providers/aws/crypto/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func ConstantTimeByteCompare(x, y []byte) (int, error) {

xLarger, yLarger := 0, 0

for i := 0; i < len(x); i++ {
for i := range x {
xByte, yByte := int(x[i]), int(y[i])

x := ((yByte - xByte) >> 8) & 1
Expand Down
4 changes: 2 additions & 2 deletions internal/report/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ func New(id string, opts Options) (*Reporter, error) {
url = ExternalServiceURL
}

restConfig := []byte(fmt.Sprintf(`{
restConfig := fmt.Appendf(nil, `{
"url": %q,
}`, url))
}`, url)

client, err := rest.New(restConfig, map[string]*keys.Config{}, rest.Logger(opts.Logger))
if err != nil {
Expand Down
15 changes: 3 additions & 12 deletions internal/wasm/sdk/internal/wasm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,10 +353,7 @@ func (i *VM) Eval(ctx context.Context,
metrics.Timer("wasm_vm_eval_call").Stop()

data := i.memory.UnsafeData(i.store)[resultAddr:]
n := bytes.IndexByte(data, 0)
if n < 0 {
n = 0
}
n := max(bytes.IndexByte(data, 0), 0)

// Skip free'ing input and result JSON as the heap will be reset next round anyway.
return data[:n], nil
Expand Down Expand Up @@ -439,10 +436,7 @@ func (i *VM) evalCompat(ctx context.Context,
}

data := i.memory.UnsafeData(i.store)[serialized:]
n := bytes.IndexByte(data, 0)
if n < 0 {
n = 0
}
n := max(bytes.IndexByte(data, 0), 0)

metrics.Timer("wasm_vm_eval_prepare_result").Stop()

Expand Down Expand Up @@ -656,10 +650,7 @@ func (i *VM) fromRegoJSON(ctx context.Context, addr int32, free bool) (any, erro
}

data := i.memory.UnsafeData(i.store)[serialized:]
n := bytes.IndexByte(data, 0)
if n < 0 {
n = 0
}
n := max(bytes.IndexByte(data, 0), 0)

// Parse the result into go types.

Expand Down
7 changes: 2 additions & 5 deletions v1/ast/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,7 @@ func compareRelatedResources(a, b []*RelatedResourceAnnotation) int {
}

func compareSchemas(a, b []*SchemaAnnotation) int {
maxLen := len(a)
if len(b) < maxLen {
maxLen = len(b)
}
maxLen := min(len(b), len(a))

for i := range maxLen {
if cmp := a[i].Compare(b[i]); cmp != 0 {
Expand Down Expand Up @@ -562,7 +559,7 @@ func attachRuleAnnotations(mod *Module) {
}

if found && j < len(cpy) {
cpy = append(cpy[:j], cpy[j+1:]...)
cpy = slices.Delete(cpy, j, j+1)
}
}
}
Expand Down
8 changes: 2 additions & 6 deletions v1/ast/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package ast

import (
"fmt"
"slices"
"sort"
"strings"

Expand Down Expand Up @@ -1006,12 +1007,7 @@ func (d *ArgErrDetail) Lines() []string {
}

func (d *ArgErrDetail) nilType() bool {
for i := range d.Have {
if types.Nil(d.Have[i]) {
return true
}
}
return false
return slices.ContainsFunc(d.Have, types.Nil)
}

// UnificationErrDetail describes a type mismatch error when two values are
Expand Down
Loading