Skip to content

Commit

Permalink
PERFORMANCE: Use StringBuilder for path replacement - #487
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed Jan 1, 2015
1 parent 6987cd8 commit 2ff26c9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 24 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.11 - 01.01.2015
* PERFORMANCE: Use StringBuilder for path replacement - https://github.com/fsprojects/Paket/issues/487

#### 0.20.10 - 01.01.2015
* PERFORMANCE: Cache feed errors - https://github.com/fsprojects/Paket/issues/487

Expand Down
54 changes: 30 additions & 24 deletions src/Paket.Core/FrameworkHandling.fs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,31 @@ type FrameworkVersion =
FrameworkVersion.V4_5_2
FrameworkVersion.V4_5_3 ]

module KnownAliases =
let Data =
[".net", "net"
"netframework", "net"
".netframework", "net"
".netcore", "netcore"
"winrt", "netcore"
"silverlight", "sl"
"windowsphone", "wp"
"windows", "win"
"windowsPhoneApp", "wpa"

"1.0", "10"
"1.1", "11"
"2.0", "20"
"3.5", "35"
"4.0", "40"
"4.5", "45"
"5.0", "50"
"8.0", "80"
"8.1", "81"
"0.0", "" ]
|> List.map (fun (p,r) -> p.ToLower(),r.ToLower())


/// Framework Identifier type.
type FrameworkIdentifier =
| DotNetFramework of FrameworkVersion
Expand All @@ -55,31 +80,12 @@ type FrameworkIdentifier =
| Silverlight of string

static member Extract(path:string) =
let knownAliases =
[".net", "net"
"netframework", "net"
".netframework", "net"
".netcore", "netcore"
"winrt", "netcore"
"silverlight", "sl"
"windowsphone", "wp"
"windows", "win"
"windowsPhoneApp", "wpa"

"1.0", "10"
"1.1", "11"
"2.0", "20"
"3.5", "35"
"4.0", "40"
"4.5", "45"
"5.0", "50"
"8.0", "80"
"8.1", "81"
"0.0", "" ]


let path =
knownAliases
|> List.fold (fun (path:string) (pattern,replacement) -> path.Replace(pattern.ToLower(),replacement.ToLower())) (path.ToLower())
let sb = new Text.StringBuilder(path.ToLower())
for pattern,replacement in KnownAliases.Data do

This comment has been minimized.

Copy link
@mexx

mexx Jan 6, 2015

Member

@forki is there a reason for replacing the fold with for loop?
StringBuilder is actually a perfect fit as state.

Data.KnownAliases
|> List.fold (fun sb -> sb.Replace) (Text.StringBuilder(path.ToLower()))
|> string
sb.Replace(pattern,replacement) |> ignore

This comment has been minimized.

Copy link
@vasily-kirichenko

vasily-kirichenko Jan 1, 2015

Contributor

I also saw this place among profiler's hotspots, but didn't know that StringBuilder can be used to do fast replaces. Great!

sb.ToString()

match path with
| "net10" | "net1" | "10" -> Some (DotNetFramework FrameworkVersion.V1)
Expand Down

0 comments on commit 2ff26c9

Please sign in to comment.