Bufferized input from channels.

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@5319 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
master
Pierre Weis 2002-12-08 21:28:23 +00:00
parent 2b57634958
commit 831a3d7f5c
1 changed files with 18 additions and 4 deletions

View File

@ -158,14 +158,28 @@ let from_string s =
c in
create next;;
let from_function = create;;
(* Perform bufferized input to improve efficiency. *)
let file_buffer_size = ref 1024;;
let from_channel ic =
let next () = input_char ic in
let len = !file_buffer_size in
let buf = String.create len in
let i = ref 0 in
let lim = ref 0 in
let next () =
if !i < !lim then begin let c = buf.[!i] in incr i; c end else begin
lim := input ic buf 0 len;
if !lim = 0 then raise End_of_file else begin
i := 1;
buf.[0]
end
end in
create next;;
let from_function f = create f;;
let stdib = from_channel stdin;;
(** The scanning buffer reading form [stdin].*)
(** The scanning buffer reading from [stdin].*)
end;;