Skip to content

Commit

Permalink
make findMatchingStep faster and slightly more readable
Browse files Browse the repository at this point in the history
  • Loading branch information
0x53A committed Apr 30, 2017
1 parent 3347802 commit 39e23a9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
14 changes: 14 additions & 0 deletions src/Paket.Core/Common/Utils.fs
Original file line number Diff line number Diff line change
Expand Up @@ -999,3 +999,17 @@ module Seq =
) |> fun (xs,ys) ->
List.rev xs :> seq<_>, List.rev ys :> seq<_>

[<RequireQualifiedAccess>]
module List =
// try to find an element in a list.
// If found, return the element and the list WITHOUT the element.
// If not found, return None.
let tryExtractOne fn values =
match List.tryFindIndex fn values with
| Some i ->
let rest = [
for i2 in 0 .. values.Length - 1 do
if i <> i2 then yield values.[i2]
]
Some values.[i], rest
| None -> None, values
22 changes: 7 additions & 15 deletions src/Paket.Core/Dependencies/PackageResolver.fs
Original file line number Diff line number Diff line change
Expand Up @@ -653,33 +653,25 @@ let Resolve (getVersionsF, getPackageDetailsF, groupName:GroupName, globalStrate

let inline fuseConflicts currentConflict priorConflictSteps conflicts =
let findMatchingStep priorConflictSteps =
priorConflictSteps // row
|> Seq.tryFindIndex (fun (_,_,lastRequirement:PackageRequirement,_,_) ->
priorConflictSteps
|> List.tryExtractOne (fun (_,_,lastRequirement:PackageRequirement,_,_) ->
let currentNames =
conflicts |> Seq.collect (fun c ->
let graphNameList =
c.Graph |> List.map (fun (pr:PackageRequirement) -> pr.Name)
c.Name :: graphNameList)
|> Seq.toArray
currentNames |> Array.contains lastRequirement.Name)
|> Option.map (fun i ->
let row = priorConflictSteps |> List.item i
let priorExceptRow =
priorConflictSteps
|> List.mapi (fun i2 v -> i2,v)
|> List.filter (fun (i2, _) -> i2 <> i)
|> List.map snd
row, priorExceptRow)

match priorConflictSteps, findMatchingStep priorConflictSteps with
| [], _ -> currentConflict
| _, Some (head, priorConflictSteps) ->

match findMatchingStep priorConflictSteps with
| None, [] -> currentConflict
| (Some head), priorConflictSteps ->
let (lastConflict, lastStep, lastRequirement, lastCompatibleVersions, lastFlags) = head
let continueConflict =
{ currentConflict with VersionsToExplore = lastConflict.VersionsToExplore }
step (Inner((continueConflict,lastStep,lastRequirement), priorConflictSteps)) stackpack lastCompatibleVersions lastFlags
// could not find a specific package - go back one step
| head :: priorConflictSteps, None ->
| None, head :: priorConflictSteps ->
let (lastConflict, lastStep, lastRequirement, lastCompatibleVersions, lastFlags) = head
let continueConflict =
{ currentConflict with VersionsToExplore = lastConflict.VersionsToExplore }
Expand Down

0 comments on commit 39e23a9

Please sign in to comment.