Skip to content

Commit 30009f7

Browse files
committed
stunnel_cache: remove ad-hoc chop implementation
This can be replaced with a List.drop. For now this is available in xapi's stdext, but it will become part of the standard library Signed-off-by: Pau Ruiz Safont <pau.safont@vates.tech>
1 parent be994de commit 30009f7

File tree

4 files changed

+8
-13
lines changed

4 files changed

+8
-13
lines changed

dune-project

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,8 @@
612612
(= :version))
613613
(xapi-stdext-pervasives
614614
(= :version))
615+
(xapi-stdext-std
616+
(= :version))
615617
(xapi-stdext-threads
616618
(= :version))
617619
(xapi-stdext-unix

ocaml/libs/stunnel/dune

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
xapi-inventory
1414
xapi-log
1515
xapi-stdext-pervasives
16+
xapi-stdext-std
1617
xapi-stdext-threads
1718
xapi-stdext-unix
1819
)

ocaml/libs/stunnel/stunnel_cache.ml

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ open Safe_resources
2727

2828
let with_lock = Xapi_stdext_threads.Threadext.Mutex.execute
2929

30+
let list_drop = Xapi_stdext_std.Listext.List.drop
31+
3032
(* Disable debug-level logging but leave higher-priority enabled. It would be
3133
* better to handle this sort of configuration in the Debug module itself.
3234
*)
@@ -93,17 +95,6 @@ let unlocked_gc () =
9395
!index ""
9496
)
9597
) ;
96-
(* Split a list at the given index to give a pair of lists.
97-
* From Xapi_stdext_std.Listext *)
98-
let rec chop i l =
99-
match (i, l) with
100-
| 0, l ->
101-
([], l)
102-
| i, h :: t ->
103-
(fun (fr, ba) -> (h :: fr, ba)) (chop (i - 1) t)
104-
| _ ->
105-
invalid_arg "chop"
106-
in
10798
let all_ids = Tbl.fold !stunnels (fun k _ acc -> k :: acc) [] in
10899
let to_gc = ref [] in
109100
(* Find the ones which are too old *)
@@ -134,8 +125,8 @@ let unlocked_gc () =
134125
List.filter (fun (idx, _) -> not (List.mem idx !to_gc)) times'
135126
in
136127
(* Sort into descending order of donation time, ie youngest first *)
137-
let times' = List.sort (fun x y -> compare (fst y) (fst x)) times' in
138-
let _youngest, oldest = chop max_stunnel times' in
128+
let times' = List.sort (fun (x, _) (y, _) -> compare y x) times' in
129+
let oldest = list_drop max_stunnel times' in
139130
let oldest_ids = List.map fst oldest in
140131
List.iter
141132
(fun x ->

opam/stunnel.opam

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ depends: [
1818
"xapi-inventory"
1919
"xapi-log" {= version}
2020
"xapi-stdext-pervasives" {= version}
21+
"xapi-stdext-std" {= version}
2122
"xapi-stdext-threads" {= version}
2223
"xapi-stdext-unix" {= version}
2324
"odoc" {with-doc}

0 commit comments

Comments
 (0)