Skip to content

Commit

Permalink
Cache platform penalty calculation - references #487
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed Jan 2, 2015
1 parent b6476a3 commit 2d85a2f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
3 changes: 3 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#### 0.20.15 - 02.01.2015
* PERFORMANCE: Cache platform penalty calculation - https://github.com/fsprojects/Paket/issues/487

#### 0.20.14 - 02.01.2015
* BUGFIX: Detect the version of a GitHub gist correctly - https://github.com/fsprojects/Paket/issues/499

Expand Down
19 changes: 14 additions & 5 deletions src/Paket.Core/PlatformMatching.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,24 @@ let inline split (path : string) =

let inline extractPlatforms path = split path |> Array.choose FrameworkIdentifier.Extract

let private penalties = Collections.Generic.Dictionary<_,_>()

let rec getPlatformPenalty (targetPlatform:FrameworkIdentifier) (packagePlatform:FrameworkIdentifier) =
if packagePlatform = targetPlatform then
0
else
targetPlatform.SupportedPlatforms
|> List.map (fun target -> getPlatformPenalty target packagePlatform)
|> List.append [maxPenalty]
|> List.min
|> fun p -> p + 1
let key = targetPlatform,packagePlatform
match penalties.TryGetValue key with
| true, penalty -> penalty
| _ ->
let penalty =
targetPlatform.SupportedPlatforms
|> List.map (fun target -> getPlatformPenalty target packagePlatform)
|> List.append [maxPenalty]
|> List.min
|> fun p -> p + 1
penalties.[key] <- penalty
penalty

let getPathPenalty (path:string) (platform:FrameworkIdentifier) =
if String.IsNullOrWhiteSpace path then
Expand Down

0 comments on commit 2d85a2f

Please sign in to comment.