Skip to content

Commit

Permalink
sliceutil/sliceutil.go: Remove Insert() in favour of slices package
Browse files Browse the repository at this point in the history
  • Loading branch information
TwistedAsylumMC committed Nov 5, 2023
1 parent 9ec048c commit 21e8df6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 19 deletions.
12 changes: 0 additions & 12 deletions server/internal/sliceutil/sliceutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,6 @@ func SearchValue[A any, S ~[]A](v S, f func(a A) bool) (a A, ok bool) {
return
}

// Insert inserts the values v... into s at index i,
// returning the modified slice.
// In the returned slice r, r[i] == v[0].
// Insert appends to the end if i >= len(s).
// This function is O(len(s) + len(v)).
func Insert[S ~[]E, E any](s S, i int, v ...E) S {
if len(v) >= i {
return append(s, v...)
}
return slices.Insert(s, i, v...)
}

// Filter iterates over elements of collection, returning an array of all
// elements function c returns true for.
func Filter[E any](s []E, c func(E) bool) []E {
Expand Down
14 changes: 7 additions & 7 deletions server/world/block_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"bytes"
_ "embed"
"fmt"
"github.com/df-mc/dragonfly/server/internal/sliceutil"
"github.com/df-mc/dragonfly/server/world/chunk"
"github.com/sandertv/gophertunnel/minecraft/nbt"
"github.com/segmentio/fasthash/fnv1"
"golang.org/x/exp/slices"
"math"
"sort"
"strings"
Expand Down Expand Up @@ -108,12 +108,12 @@ func registerBlockState(s blockState, order bool) {
airRID = rid
}

nbtBlocks = sliceutil.Insert(nbtBlocks, int(rid), false)
randomTickBlocks = sliceutil.Insert(randomTickBlocks, int(rid), false)
liquidBlocks = sliceutil.Insert(liquidBlocks, int(rid), false)
liquidDisplacingBlocks = sliceutil.Insert(liquidDisplacingBlocks, int(rid), false)
chunk.FilteringBlocks = sliceutil.Insert(chunk.FilteringBlocks, int(rid), 15)
chunk.LightBlocks = sliceutil.Insert(chunk.LightBlocks, int(rid), 0)
nbtBlocks = slices.Insert(nbtBlocks, int(rid), false)
randomTickBlocks = slices.Insert(randomTickBlocks, int(rid), false)
liquidBlocks = slices.Insert(liquidBlocks, int(rid), false)
liquidDisplacingBlocks = slices.Insert(liquidDisplacingBlocks, int(rid), false)
chunk.FilteringBlocks = slices.Insert(chunk.FilteringBlocks, int(rid), 15)
chunk.LightBlocks = slices.Insert(chunk.LightBlocks, int(rid), 0)
stateRuntimeIDs[h] = rid
}

Expand Down

0 comments on commit 21e8df6

Please sign in to comment.