diff --git a/lib-lwt/cachet_lwt.ml b/lib-lwt/cachet_lwt.ml index 347f988..07f43d8 100644 --- a/lib-lwt/cachet_lwt.ml +++ b/lib-lwt/cachet_lwt.ml @@ -20,8 +20,8 @@ let blit_to_bytes t ~src_off:logical_address buf ~dst_off ~len = if len < 0 || dst_off < 0 || dst_off > Bytes.length buf - len then invalid_arg "Cachet_lwt.blit_to_bytes"; let pagesize = Cachet.pagesize t in - let off = logical_address land ((1 lsl pagesize) - 1) in - if is_aligned off && (1 lsl pagesize) - off >= len then + let off = logical_address land (pagesize - 1) in + if is_aligned off && pagesize - off >= len then load t ~len logical_address >|= function | None -> out_of_bounds logical_address | Some slice -> diff --git a/lib-lwt/cachet_lwt.mli b/lib-lwt/cachet_lwt.mli index a271226..79ad68b 100644 --- a/lib-lwt/cachet_lwt.mli +++ b/lib-lwt/cachet_lwt.mli @@ -21,7 +21,7 @@ val get_int8 : 'fd Cachet.t -> int -> int Lwt.t val get_uint8 : 'fd Cachet.t -> int -> int Lwt.t (** [get_uint8 t logical_address] is [t]'s unsigned 8-bit integer starting at byte index [logical_address]. - + @raise Out_of_bounds if [logical_address] is not accessible. *) val get_uint16_ne : 'fd Cachet.t -> int -> int Lwt.t diff --git a/lib/cachet.ml b/lib/cachet.ml index b322cd5..fec54ff 100644 --- a/lib/cachet.ml +++ b/lib/cachet.ml @@ -441,7 +441,7 @@ type 'fd t = { and 'fd map = 'fd -> pos:int -> int -> bigstring let fd { fd; _ } = fd -let pagesize { pagesize; _ } = pagesize +let pagesize { pagesize; _ } = 1 lsl pagesize let copy t = { @@ -477,7 +477,6 @@ let load t logical_address = let none : slice option = None let cache_miss t = t.metrics.cache_miss let cache_hit t = t.metrics.cache_hit -let pagesize t = 1 lsl t.pagesize let load t ?(len = 1) logical_address = if len > 1 lsl t.pagesize then diff --git a/lib/cachet.mli b/lib/cachet.mli index 76092b3..b91820f 100644 --- a/lib/cachet.mli +++ b/lib/cachet.mli @@ -240,8 +240,6 @@ val cache_hit : 'fd t -> int val cache_miss : 'fd t -> int (** [cache_miss t] is the number of times a load didn't hit the cache. *) -val pagesize : 'fd t -> int - val copy : 'fd t -> 'fd t (** [copy t] creates a new, empty cache using the same [map] function. *)