diff --git a/master_changes.md b/master_changes.md index f5a6340d329..712fd68f77b 100644 --- a/master_changes.md +++ b/master_changes.md @@ -200,6 +200,7 @@ users) * `OpamFile.Repos_config.t`: change the type to not allow repositories without an URL [#6249 @kit-ty-kate] ## opam-core + * `OpamStd.List.split`: Improve performance [#6210 @kit-ty-kate] * `OpamStd.Sys.{get_terminal_columns,uname,getconf,guess_shell_compat}`: Harden the process calls to account for failures [#6230 @kit-ty-kate - fix #6215] * `OpamStd.Sys.getconf`: was removed, replaced by `get_long_bit` [#6217 @kit-ty-kate] * `OpamStd.Sys.get_long_bit`: was added, which returns the output of the `getconf LONG_BIT` command [#6217 @kit-ty-kate] diff --git a/src/core/opamStd.ml b/src/core/opamStd.ml index 226af7effb3..2b766533742 100644 --- a/src/core/opamStd.ml +++ b/src/core/opamStd.ml @@ -692,9 +692,25 @@ module OpamString = struct let rcut_at = cut_at_aux String.rindex let split s c = - (* old compat version (Re 1.2.0) - {[Re_str.split (Re_str.regexp (Printf.sprintf "[%c]+" c)) s]} *) - Re.(split (compile (rep1 (char c)))) s + let rec loop acc i slice_start len s c = + if (i : int) < (len : int) then + if s.[i] = (c : char) then + let acc = + if (slice_start : int) < (i : int) then + String.sub s slice_start (i - slice_start) :: acc + else + acc + in + let i = i+1 in + loop acc i i len s c + else + loop acc (i+1) slice_start len s c + else if (i : int) = (slice_start : int) then + acc + else + String.sub s slice_start (len - slice_start) :: acc + in + List.rev (loop [] 0 0 (String.length s) s c) let split_delim s c = let tokens = Re.(split_full (compile (char c)) s) in @@ -1160,9 +1176,9 @@ module OpamSys = struct | SH_fish -> Some (List.fold_left Filename.concat (home ".config") ["fish"; "config.fish"]) | SH_zsh -> - let zsh_home f = + let zsh_home f = try Filename.concat (Env.get "ZDOTDIR") f - with Not_found -> home f in + with Not_found -> home f in Some (zsh_home ".zshrc") | SH_bash -> let shell =