Revision: 425
Author: ygrekheretix
Date: Tue Nov 12 17:01:25 2013 UTC
Log: faster Array.exists (Closes issue 21)
http://code.google.com/p/ocaml-extlib/source/detail?r=425
Modified:
/trunk/extlib/extArray.ml
=======================================
--- /trunk/extlib/extArray.ml Tue Nov 1 14:08:10 2011 UTC
+++ /trunk/extlib/extArray.ml Tue Nov 12 17:01:25 2013 UTC
@@ -46,14 +46,14 @@
in
loop 0
+exception Exists
+
let exists p xs =
- let n = length xs in
- let rec loop i =
- if i = n then false
- else if p xs.(i) then true
- else loop (succ i)
- in
- loop 0
+ try
+ for i = 0 to Array.length xs - 1 do
+ if p xs.(i) then raise Exists
+ done; false
+ with Exists -> true
let mem a xs =
let n = length xs in