Commits

Sebastien Mondet  committed 5fdd795

Try to optimize lwt_count_lines

  • Participants
  • Parent commits d9664ca

Comments (0)

Files changed (1)

File fastqbench.ml

 
 let lwt_count_lines ~buffer_size file =
   let count = ref 0 in
+  let read_line i =
+    Lwt.catch (fun () -> Lwt_io.read_line  i >>= fun l -> return (Some l))
+      (fun _ -> return None) in
   Lwt_io.with_file ~buffer_size ~mode:Lwt_io.input file (fun i ->
     let rec loop () =
-      Lwt.catch 
-        (fun () ->
-          Lwt_io.read_line i >>= fun _ ->
-          incr count;
-          loop ())
-        (fun exn -> return ()) in
+      read_line i
+      >>= function
+      | Some s -> incr count; loop ()
+      | None -> return () in
     loop ())
   >>= fun () ->
   return (!count / 4)