From 21e8df605bee304e6ad6eb0d8b60417b1ae4b425 Mon Sep 17 00:00:00 2001 From: TwistedAsylumMC Date: Sun, 5 Nov 2023 12:17:16 +0000 Subject: [PATCH] sliceutil/sliceutil.go: Remove Insert() in favour of slices package --- server/internal/sliceutil/sliceutil.go | 12 ------------ server/world/block_state.go | 14 +++++++------- 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/server/internal/sliceutil/sliceutil.go b/server/internal/sliceutil/sliceutil.go index b9c602334..739ec8d71 100644 --- a/server/internal/sliceutil/sliceutil.go +++ b/server/internal/sliceutil/sliceutil.go @@ -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 { diff --git a/server/world/block_state.go b/server/world/block_state.go index 81199f37d..7f5c98147 100644 --- a/server/world/block_state.go +++ b/server/world/block_state.go @@ -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" @@ -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 }