From: Brendan Hansen Date: Wed, 6 Dec 2023 16:38:50 +0000 (-0600) Subject: fixed: implementation of `array.remove` and `array.filter` X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=d04fcb3da9de7e951d08f996b5b76b159fa76aec;p=onyx.git fixed: implementation of `array.remove` and `array.filter` --- diff --git a/core/container/array.onyx b/core/container/array.onyx index 0282fba3..338ffb9f 100644 --- a/core/container/array.onyx +++ b/core/container/array.onyx @@ -221,7 +221,10 @@ remove :: (arr: &[..] $T, elem: T) { while i := 0; i < arr.count - move { defer i += 1; - if arr.data[i + move] == elem do move += 1; + while i + move < arr.count && arr.data[i + move] == elem { + move += 1; + } + if move != 0 do arr.data[i] = arr.data[i + move]; } @@ -309,8 +312,12 @@ filter :: macro (arr: &[..] $T, body: Code) { while i := 0; i < arr.count - move { defer i += 1; - it := arr.data[i]; - if !(#unquote body(it)) do move += 1; + while i + move < arr.count { + it := arr.data[i + move]; + if #unquote body(it) do break; + move += 1; + } + if move != 0 do arr.data[i] = arr.data[i + move]; }