git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Faster array equality
commit293c4a7fa890baed95e2cb2f2f7536362c3a30c4 authorGary Burgess <gary.burgess@gmail.com> dateTue 1 Jul 2014, 16:12 (12 years ago) parent4c7733c
1 file changed+14−3
prelude/prelude.purs+14−3
prelude/prelude.purs+14−3
@@ -270,10 +270,21 @@ module Prelude
270270 (==) = refEq
271271 (/=) = refIneq
272272
273+ foreign import eqArrayImpl
274+ "function eqArrayImpl(f) {\
275+ \ return function(xs) {\
276+ \ return function(ys) {\
277+ \ if (xs.length !== ys.length) return false;\
278+ \ for (var i = 0; i < xs.length; i++) {\
279+ \ if (!f(xs[i])(ys[i])) return false;\
280+ \ }\
281+ \ return true;\
282+ \ };\
283+ \ };\
284+ \}" :: forall a. (a -> a -> Boolean) -> [a] -> [a] -> Boolean
285+
273286 instance eqArray :: (Eq a) => Eq [a] where
274− (==) [] [] = true
275− (==) (x:xs) (y:ys) = x == y && xs == ys
276− (==) _ _ = false
287+ (==) xs ys = eqArrayImpl (==) xs ys
277288 (/=) xs ys = not (xs == ys)
278289
279290 data Ordering = LT | GT | EQ