From 3b5c6d2638ea8d9c4d6c1dc54ce823aba62bcaeb Mon Sep 17 00:00:00 2001 From: Mark Eibes Date: Tue, 13 Jun 2023 20:26:29 +0200 Subject: [PATCH 1/5] Add foreign implementation for push --- src/Data/Array/ST.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Data/Array/ST.js b/src/Data/Array/ST.js index 3f4fa21..a9953f3 100644 --- a/src/Data/Array/ST.js +++ b/src/Data/Array/ST.js @@ -105,3 +105,11 @@ export const toAssocArrayImpl = function (xs) { for (var i = 0; i < n; i++) as[i] = { value: xs[i], index: i }; return as; }; + +export const push = function (a) { + return function (xs) { + return function () { + return xs.push(a); + }; + }; + }; From 1196cb6867a351a7787c3bdff48569715927044e Mon Sep 17 00:00:00 2001 From: Mark Eibes Date: Tue, 13 Jun 2023 20:27:12 +0200 Subject: [PATCH 2/5] Use foreign implementation for push --- src/Data/Array/ST.purs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Data/Array/ST.purs b/src/Data/Array/ST.purs index e95864c..7bc2d9d 100644 --- a/src/Data/Array/ST.purs +++ b/src/Data/Array/ST.purs @@ -181,8 +181,7 @@ foreign import popImpl -- | Append an element to the end of a mutable array. Returns the new length of -- | the array. -push :: forall h a. a -> STArray h a -> ST h Int -push a = runSTFn2 pushAllImpl [ a ] +foreign import push :: forall h a. a -> STArray h a -> ST h Int -- | Append the values in an immutable array to the end of a mutable array. -- | Returns the new length of the mutable array. From 2a3276a25e659502bdb48b2e0878b50608d9f871 Mon Sep 17 00:00:00 2001 From: Mark Eibes Date: Tue, 13 Jun 2023 20:33:46 +0200 Subject: [PATCH 3/5] Add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a3ec97e..9540992 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ New features: Bugfixes: Other improvements: + - Implements `ST.push` via a call to JavaScript's native `push` instead of `pushAll` (#236 by @i-am-the-slime) ## [v7.2.1](https://github.com/purescript/purescript-arrays/releases/tag/v7.2.1) - 2023-06-13 From 9e02babc036f12e5a85fae124e654f615732cce1 Mon Sep 17 00:00:00 2001 From: Mark Eibes Date: Fri, 16 Jun 2023 21:23:46 +0200 Subject: [PATCH 4/5] Update src/Data/Array/ST.js Co-authored-by: Thomas Honeyman --- src/Data/Array/ST.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/Data/Array/ST.js b/src/Data/Array/ST.js index a9953f3..2795f00 100644 --- a/src/Data/Array/ST.js +++ b/src/Data/Array/ST.js @@ -106,10 +106,6 @@ export const toAssocArrayImpl = function (xs) { return as; }; -export const push = function (a) { - return function (xs) { - return function () { - return xs.push(a); - }; - }; - }; +export const pushImpl = function (a, xs) { + return xs.push(a); +}; From 527c2eb30fff43e50725804dbf141a8db7284796 Mon Sep 17 00:00:00 2001 From: Mark Eibes Date: Fri, 16 Jun 2023 21:29:48 +0200 Subject: [PATCH 5/5] Update ST.purs --- src/Data/Array/ST.purs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Data/Array/ST.purs b/src/Data/Array/ST.purs index 7bc2d9d..5ff3c1a 100644 --- a/src/Data/Array/ST.purs +++ b/src/Data/Array/ST.purs @@ -181,7 +181,10 @@ foreign import popImpl -- | Append an element to the end of a mutable array. Returns the new length of -- | the array. -foreign import push :: forall h a. a -> STArray h a -> ST h Int +push :: forall h a. a -> (STArray h a) -> ST h Int +push = runSTFn2 pushImpl + +foreign import pushImpl :: forall h a. STFn2 a (STArray h a) h Int -- | Append the values in an immutable array to the end of a mutable array. -- | Returns the new length of the mutable array.