Skip to content

Commit

Permalink
Reduce allocations in opamVersionCompare
Browse files Browse the repository at this point in the history
Test-case:

    let ()
      let x0 = Gc.stat () in
      assert (OpamVersionCompare.compare "1.2.3" "1.02.3" == 0);
      let x1 = Gc.stat () in
      Printf.printf "minor_words: %.0f\n" (x1.minor_words -. x0.minor_words)

Before: minor_words: 156
After:  minor_words: 84
  • Loading branch information
talex5 committed Aug 7, 2024
1 parent 73a686a commit cf351c6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
1 change: 1 addition & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ users)
## Internal
* Stop using polymorphic comparison when comparing `OpamTypes.switch_selections` [#6102 @kit-ty-kate]
* Remove the meta opam packages opam and opam-admin [#6115 @kit-ty-kate]
* Reduce allocations in OpamVersionCompare [#6144 @talex5]

## Internal: Windows

Expand Down
8 changes: 3 additions & 5 deletions src/core/opamVersionCompare.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@ let is_digit = function
(* [skip_while_from i f w m] yields the index of the leftmost character
* in the string [s], starting from [i], and ending at [m], that does
* not satisfy the predicate [f], or [length w] if no such index exists. *)
let skip_while_from i f w m =
let rec loop i =
if i = m then i
else if f w.[i] then loop (i + 1) else i
in loop i
let rec skip_while_from i f w m =
if i = m then i
else if f w.[i] then skip_while_from (i + 1) f w m else i
;;

(* splits a version into (epoch,rest), without the separating ':'. The
Expand Down

0 comments on commit cf351c6

Please sign in to comment.