From 6943771bdfe5342edbecce54d6bda817f5cd5ac7 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Thu, 3 Nov 2016 23:49:50 +0100 Subject: [PATCH] remove `CCAllocCache` --- _oasis | 2 +- doc/intro.txt | 1 - src/data/CCAllocCache.ml | 75 --------------------------------------- src/data/CCAllocCache.mli | 35 ------------------ 4 files changed, 1 insertion(+), 112 deletions(-) delete mode 100644 src/data/CCAllocCache.ml delete mode 100644 src/data/CCAllocCache.mli diff --git a/_oasis b/_oasis index 61d60ba3..146b6ee4 100644 --- a/_oasis +++ b/_oasis @@ -59,7 +59,7 @@ Library "containers_data" CCPersistentHashtbl, CCDeque, CCFQueue, CCBV, CCMixtbl, CCMixmap, CCRingBuffer, CCIntMap, CCPersistentArray, CCMixset, CCHashconsedSet, CCGraph, CCHashSet, CCBitField, - CCHashTrie, CCWBTree, CCRAL, CCAllocCache, + CCHashTrie, CCWBTree, CCRAL, CCImmutArray, CCHet, CCZipper BuildDepends: bytes # BuildDepends: bytes, bisect_ppx diff --git a/doc/intro.txt b/doc/intro.txt index e2eeb355..53280745 100644 --- a/doc/intro.txt +++ b/doc/intro.txt @@ -70,7 +70,6 @@ such as: Various data structures. {!modules: -CCAllocCache CCBitField CCBV CCCache diff --git a/src/data/CCAllocCache.ml b/src/data/CCAllocCache.ml deleted file mode 100644 index 3d47c8c7..00000000 --- a/src/data/CCAllocCache.ml +++ /dev/null @@ -1,75 +0,0 @@ - -(* This file is free software, part of Logtk. See file "license" for more details. *) - -(** {1 Simple Cache for Allocations} *) - -module Arr = struct - type 'a t = { - caches: 'a array array; - (* 2-dim array of cached arrays. The 2-dim array is flattened into - one dimension *) - max_buck_size: int; - (* number of cached arrays per length *) - sizes: int array; - (* number of cached arrays in each bucket *) - } - - let create ?(buck_size=16) n = - if n<1 then invalid_arg "AllocCache.Arr.create"; - { max_buck_size=buck_size; - sizes=Array.make n 0; - caches=Array.make (n * buck_size) [||]; - } - - let make c i x = - if i=0 then [||] - else if i 0 && n < Array.length c.sizes then ( - let bs = c.sizes.(n) in - if bs < c.max_buck_size then ( - (* store [a] *) - c.caches.(n * c.max_buck_size + bs) <- a; - c.sizes.(n) <- bs + 1 - ) - ) - - let with_ c i x ~f = - let a = make c i x in - try - let ret = f a in - free c a; - ret - with e -> - free c a; - raise e -end - -(*$inject - let c = Arr.create ~buck_size:2 20 - -*) - -(*$Q - Q.small_int (fun n -> Array.length (Arr.make c n '_') = n) -*) - -(*$T - let a = Arr.make c 1 '_' in Array.length a = 1 - let a = Arr.make c 2 '_' in Array.length a = 2 - let a = Arr.make c 3 '_' in Array.length a = 3 - let a = Arr.make c 4 '_' in Array.length a = 4 -*) - - diff --git a/src/data/CCAllocCache.mli b/src/data/CCAllocCache.mli deleted file mode 100644 index d8538a96..00000000 --- a/src/data/CCAllocCache.mli +++ /dev/null @@ -1,35 +0,0 @@ - -(* This file is free software, part of Logtk. See file "license" for more details. *) - -(** {1 Simple Cache for Allocations} - - Be very careful not to use-after-free or double-free. - - {b NOT THREAD SAFE} - {b status: experimental} - - @since 0.15 - -*) - -module Arr : sig - type 'a t - (** Cache for 'a arrays *) - - val create: ?buck_size:int -> int -> 'a t - (** [create n] makes a new cache of arrays up to length [n] - @param buck_size number of arrays cached for each array length - @param n maximum size of arrays put in cache *) - - val make : 'a t -> int -> 'a -> 'a array - (** [make cache i x] is like [Array.make i x], - but might return a cached array instead of allocating one. - {b NOTE}: if the array is already allocated then it - will NOT be filled with [x] *) - - val free : 'a t -> 'a array -> unit - (** Return array to the cache. The array's elements will not be GC'd *) - - val with_ : 'a t -> int -> 'a -> f:('a array -> 'b) -> 'b - (** Combines {!make} and {!free} *) -end