Skip to content

Commit

Permalink
speedup
Browse files Browse the repository at this point in the history
  • Loading branch information
kit-ty-kate committed Sep 25, 2024
1 parent 9f19452 commit ef4b210
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions src/core/opamStd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -692,27 +692,27 @@ module OpamString = struct
let rcut_at = cut_at_aux String.rindex

let split s c =
let acc = ref [] in
let in_run = ref false in
let slice_start = ref 0 in
let len = String.length s in
for i=0 to len-1 do
if (String.get s i : char) = (c : char) then (
if not !in_run then (
if (i : int) > (!slice_start : int) then
acc := String.sub s !slice_start (i - !slice_start) :: !acc;
in_run := true;
)
) else (
if !in_run then (
in_run := false;
slice_start := i;
)
)
done;
if not !in_run && (!slice_start : int) < (len : int) then
acc := String.sub s !slice_start (len - !slice_start) :: !acc;
List.rev !acc
let rec loop acc in_run slice_start len i s c =
if (i : int) < (len : int) then
if (String.get s i : char) = (c : char) then
if not in_run then
if (i : int) > (slice_start : int) then
loop (String.sub s slice_start (i - slice_start) :: acc)
true slice_start len (i + 1) s c
else
loop acc true slice_start len (i + 1) s c
else
loop acc in_run slice_start len (i + 1) s c
else if in_run then
loop acc false i len (i + 1) s c
else
loop acc in_run slice_start len (i + 1) s c
else if not in_run && (slice_start : int) < (len : int) then
String.sub s slice_start (len - slice_start) :: acc
else
acc
in
List.rev (loop [] false 0 (String.length s) 0 s c)

let split_delim s c =
let tokens = Re.(split_full (compile (char c)) s) in
Expand Down

0 comments on commit ef4b210

Please sign in to comment.