aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorArnaud Spiwack2014-02-24 16:47:59 +0100
committerArnaud Spiwack2014-02-24 16:47:59 +0100
commit23eeacf4c22055a60b9f64ba308f9198ba4d938b (patch)
treef2e08461fbc2eba6eea27b757d8cde1ab7b68263 /lib
parent1bb2ee934bc2082865ee64f539497f3bc292a439 (diff)
IStream: change type of thunk, spare allocations.
Two changes: - 'a Lazy.t becomes unit -> 'a - 'a t becomes 'a u (the view type) This spares two Lazy.force, and leverages Lazy.lazy_from_fun. Considering Lazy.force is fairly slow, in particular because of the write-barrier, this should be beneficial.
Diffstat (limited to 'lib')
-rw-r--r--lib/iStream.ml6
-rw-r--r--lib/iStream.mli14
2 files changed, 10 insertions, 10 deletions
diff --git a/lib/iStream.ml b/lib/iStream.ml
index 65a336dafd..1d9f55998e 100644
--- a/lib/iStream.ml
+++ b/lib/iStream.ml
@@ -6,11 +6,11 @@
(* * GNU Lesser General Public License Version 2.1 *)
(************************************************************************)
-type ('a,'r) peek =
+type ('a,'r) u =
| Nil
| Cons of 'a * 'r
-type 'a node = ('a,'a t) peek
+type 'a node = ('a,'a t) u
and 'a t = 'a node Lazy.t
@@ -18,7 +18,7 @@ let empty = Lazy.lazy_from_val Nil
let cons x s = Lazy.lazy_from_val (Cons (x, s))
-let thunk s = lazy (Lazy.force (Lazy.force s))
+let thunk = Lazy.lazy_from_fun
let rec force s = match Lazy.force s with
| Nil -> ()
diff --git a/lib/iStream.mli b/lib/iStream.mli
index fd3fa6c503..9e4dec415a 100644
--- a/lib/iStream.mli
+++ b/lib/iStream.mli
@@ -15,6 +15,11 @@
type +'a t
(** Type of pure streams. *)
+type ('a,'r) u =
+| Nil
+| Cons of 'a * 'r
+(** View type to decompose and build streams. *)
+
(** {6 Constructors} *)
val empty : 'a t
@@ -23,7 +28,7 @@ val empty : 'a t
val cons : 'a -> 'a t -> 'a t
(** Append an element in front of a stream. *)
-val thunk : 'a t Lazy.t -> 'a t
+val thunk : (unit -> ('a,'a t) u) -> 'a t
(** Internalize the lazyness of a stream. *)
(** {6 Destructors} *)
@@ -31,12 +36,7 @@ val thunk : 'a t Lazy.t -> 'a t
val is_empty : 'a t -> bool
(** Whethere a stream is empty. *)
-type ('a,'r) peek =
-| Nil
-| Cons of 'a * 'r
-(** View type for {!peek} *)
-
-val peek : 'a t -> ('a , 'a t) peek
+val peek : 'a t -> ('a , 'a t) u
(** Return the head and the tail of a stream, if any. *)
(** {6 Standard operations}