Skip to content

Commit 9678b4d

Browse files
committed
xapi-stdext-std: replace String.filter_chars with Astring.filter
The former didn't have any tests and the performance is unknown Signed-off-by: Pau Ruiz Safont <pau.ruizsafont@cloud.com> Signed-off-by: Pau Ruiz Safont <pau.safont@vates.tech>
1 parent 6a3853e commit 9678b4d

6 files changed

Lines changed: 3 additions & 25 deletions

File tree

ocaml/libs/tgroup/dune

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
(name tgroup)
33
(modules tgroup)
44
(public_name tgroup)
5-
(libraries unix xapi-log xapi-stdext-unix xapi-stdext-std))
5+
(libraries astring unix xapi-log xapi-stdext-unix))
66

77
(test
88
(name test_tgroup)

ocaml/libs/tgroup/tgroup.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ module Group = struct
7070
| _ ->
7171
false
7272

73-
let sanitize s =
74-
Xapi_stdext_std.Xstringext.String.filter_chars s is_alphanum
73+
let sanitize s = Astring.String.filter is_alphanum s
7574

7675
let make ?user_agent subject_sid =
7776
let user_agent =

ocaml/libs/xapi-stdext/lib/xapi-stdext-std/xstringext.ml

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -103,22 +103,6 @@ module String = struct
103103
) else
104104
s
105105

106-
let filter_chars s valid =
107-
let badchars = ref false in
108-
let buf = Buffer.create 0 in
109-
for i = 0 to String.length s - 1 do
110-
if !badchars then (
111-
if valid s.[i] then Buffer.add_char buf s.[i]
112-
) else if not (valid s.[i]) then (
113-
Buffer.add_substring buf s 0 i ;
114-
badchars := true
115-
)
116-
done ;
117-
if !badchars then
118-
Buffer.contents buf
119-
else
120-
s
121-
122106
let map_unlikely s f =
123107
let changed = ref false in
124108
let m = ref 0 in

ocaml/libs/xapi-stdext/lib/xapi-stdext-std/xstringext.mli

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ module String : sig
3434
val replace : string -> string -> string -> string
3535
(** replace all [f] substring in [s] by [t] *)
3636

37-
val filter_chars : string -> (char -> bool) -> string
38-
(** filter chars from a string *)
39-
4037
val map_unlikely : string -> (char -> string option) -> string
4138
(** map a string trying to fill the buffer by chunk *)
4239

ocaml/xe-cli/dune

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
xapi-backtrace
1818
xapi-cli-protocol
1919
xapi-stdext-pervasives
20-
xapi-stdext-std
2120
xapi-stdext-unix
2221
)
2322
)

ocaml/xe-cli/newcli.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
*)
1414
(* New cli talking to the in-server cli interface *)
1515

16-
module Stringext = Xapi_stdext_std.Xstringext.String
1716
open Xapi_stdext_pervasives
1817
open Cli_protocol
1918

@@ -316,7 +315,7 @@ let parse_args =
316315
|| (extra_args.[!i] = ',' && extra_args.[!i - 1] <> '\\')
317316
then (
318317
let seg = String.sub extra_args !pos (!i - !pos) in
319-
l := Stringext.filter_chars seg (( <> ) '\\') :: !l ;
318+
l := Astring.String.filter (( <> ) '\\') seg :: !l ;
320319
incr i ;
321320
pos := !i
322321
) else

0 commit comments

Comments
 (0)