-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
47 changed files
with
3,050 additions
and
2,015 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
(* The MIT License | ||
Copyright (c) 2021 Clément Pascutto <clement@tarides.com> | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. *) | ||
|
||
open! Import | ||
|
||
type t = { mutable buffer : bytes; mutable position : int } | ||
|
||
external unsafe_blit_string : string -> int -> bytes -> int -> int -> unit | ||
= "caml_blit_string" | ||
[@@noalloc] | ||
(** Bytes.unsafe_blit_string not available in OCaml 4.08. *) | ||
|
||
let create n = { buffer = Bytes.create n; position = 0 } | ||
|
||
let write_with (write : string -> int -> int -> unit) b = | ||
write (Bytes.unsafe_to_string b.buffer) 0 b.position | ||
|
||
let length b = b.position | ||
let is_empty b = b.position = 0 | ||
let clear b = b.position <- 0 | ||
|
||
let resize b more = | ||
let old_pos = b.position in | ||
let old_len = Bytes.length b.buffer in | ||
let new_len = ref old_len in | ||
while old_pos + more > !new_len do | ||
new_len := 2 * !new_len | ||
done; | ||
let new_buffer = Bytes.create !new_len in | ||
Bytes.blit b.buffer 0 new_buffer 0 b.position; | ||
b.buffer <- new_buffer | ||
|
||
let add_substring b s ~off ~len = | ||
let new_position = b.position + len in | ||
if new_position > Bytes.length b.buffer then resize b len; | ||
unsafe_blit_string s off b.buffer b.position len; | ||
b.position <- new_position | ||
|
||
let blit ~src ~src_off ~dst ~dst_off ~len = | ||
assert (src_off + len <= src.position); | ||
Bytes.blit src.buffer src_off dst dst_off len | ||
|
||
let add_string b s = add_substring b s ~off:0 ~len:(String.length s) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
(* The MIT License | ||
Copyright (c) 2021 Clément Pascutto <clement@tarides.com> | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. *) | ||
|
||
(** Extensible buffers with non-allocating access to the buffer's contents. *) | ||
|
||
type t | ||
(** The type of buffers. *) | ||
|
||
val create : int -> t | ||
(** [create n] is a fresh buffer with initial size [n]. *) | ||
|
||
val length : t -> int | ||
(** [length b] is the number of bytes contained in the buffer. *) | ||
|
||
val is_empty : t -> bool | ||
(** [is_empty t] iff [t] contains 0 characters. *) | ||
|
||
val clear : t -> unit | ||
(** [clear t] clears the data contained in [t]. It does not reset the buffer to | ||
its initial size. *) | ||
|
||
val add_substring : t -> string -> off:int -> len:int -> unit | ||
(** [add_substring t s ~off ~len] appends the substring | ||
[s.(off) .. s.(off + len - 1)] at the end of [t], resizing [t] if necessary. *) | ||
|
||
val add_string : t -> string -> unit | ||
(** [add_string t s] appends [s] at the end of [t], resizing [t] if necessary. *) | ||
|
||
val write_with : (string -> int -> int -> unit) -> t -> unit | ||
(** [write_with writer t] uses [writer] to write the contents of [t]. [writer] | ||
takes a string to write, an offset and a length. *) | ||
|
||
val blit : src:t -> src_off:int -> dst:bytes -> dst_off:int -> len:int -> unit | ||
(** [blit] copies [len] bytes from the buffer [src], starting at offset | ||
[src_off], into the supplied bytes [dst], starting at offset [dst_off]. *) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
(library | ||
(public_name index.eio) | ||
(name index_eio) | ||
(optional) | ||
(libraries fmt fmt.tty index logs logs.threaded threads.posix unix eio | ||
eio.core cstruct mtime mtime.clock.os optint progress)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module Int63 = Optint.Int63 | ||
|
||
type int63 = Int63.t | ||
|
||
module Mtime = struct | ||
include Mtime | ||
|
||
let span_to_s span = Mtime.Span.to_float_ns span *. 1e-9 | ||
let span_to_us span = Mtime.Span.to_float_ns span *. 1e-3 | ||
end |
Oops, something went wrong.