Skip to content

Commit

Permalink
removed unnecessary memory allocations
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudRoutine committed Jan 16, 2016
1 parent ce6ac71 commit d267615
Show file tree
Hide file tree
Showing 14 changed files with 53 additions and 38 deletions.
2 changes: 1 addition & 1 deletion src/Paket.Core/BindingRedirects.fs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ let private applyBindingRedirects isFirstGroup cleanBindingRedirects bindingRedi

let isMarked e =
match tryGetElement (Some bindingNs) "Paket" e with
| Some e -> e.Value.Trim().ToLower() = "true"
| Some e -> String.equalsIgnoreCase (e.Value.Trim()) "true"
| None -> false

let nsManager = XmlNamespaceManager(NameTable());
Expand Down
6 changes: 3 additions & 3 deletions src/Paket.Core/DependenciesFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ module DependenciesFileParser =
let inline parsePrerelease (texts : string list) =
match texts |> List.filter ((<>) "") with
| [] -> PreReleaseStatus.No
| [x] when x.ToLower() = "prerelease" -> PreReleaseStatus.All
| [x] when String.equalsIgnoreCase x "prerelease" -> PreReleaseStatus.All
| _ -> PreReleaseStatus.Concrete texts

if String.IsNullOrWhiteSpace text then VersionRequirement(VersionRange.AtLeast("0"),PreReleaseStatus.No) else
Expand Down Expand Up @@ -627,8 +627,8 @@ type DependenciesFile(fileName,groups:Map<GroupName,DependenciesGroup>, textRepr
| Some found ->
let pos = ref (found + 1)
let skipped = ref false
while !pos < textRepresentation.Length - 1 && (String.IsNullOrWhiteSpace textRepresentation.[!pos] || textRepresentation.[!pos].ToLower().StartsWith("source")) do
if textRepresentation.[!pos].ToLower().StartsWith("source") then
while !pos < textRepresentation.Length - 1 && (String.IsNullOrWhiteSpace textRepresentation.[!pos] || String.startsWithIgnoreCase "source" textRepresentation.[!pos]) do
if String.startsWithIgnoreCase "source" textRepresentation.[!pos] then
skipped := true
pos := !pos + 1

Expand Down
4 changes: 2 additions & 2 deletions src/Paket.Core/FrameworkHandling.fs
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,10 @@ module FrameworkDetection =
let path = path.Replace("\\", "/").ToLower()
let fi = new FileInfo(path)

if path.Contains("lib/" + fi.Name.ToLower()) then Some(DotNetFramework(FrameworkVersion.V1))
if String.containsIgnoreCase ("lib/" + fi.Name) path then Some(DotNetFramework(FrameworkVersion.V1))
else
let startPos = path.LastIndexOf("lib/")
let endPos = path.LastIndexOf(fi.Name.ToLower())
let endPos = path.LastIndexOf(fi.Name,StringComparison.OrdinalIgnoreCase)
if startPos < 0 || endPos < 0 then None
else
path.Substring(startPos + 4, endPos - startPos - 5)
Expand Down
8 changes: 4 additions & 4 deletions src/Paket.Core/InstallModel.fs
Original file line number Diff line number Diff line change
Expand Up @@ -275,18 +275,18 @@ module InstallModel =
references |> Seq.fold (addFrameworkAssemblyReference) (installModel:InstallModel)

let filterBlackList (installModel:InstallModel) =
let inline checkExt str ext = str |> toLower |> endsWith ext

let includeReferences = function
| Reference.Library lib -> not (checkExt lib ".dll" || checkExt lib ".exe")
| Reference.Library lib -> not (String.endsWithIgnoreCase ".dll" lib || String.endsWithIgnoreCase ".exe" lib )
| Reference.TargetsFile targetsFile ->
(not (checkExt targetsFile ".props" || checkExt targetsFile ".targets"))
(not (String.endsWithIgnoreCase ".props" targetsFile|| String.endsWithIgnoreCase ".targets" targetsFile))
| _ -> false

let excludeSatelliteAssemblies = function
| Reference.Library lib -> lib.EndsWith ".resources.dll"
| _ -> false

let blacklisted (blacklist:string list) (file:string) = blacklist |> List.exists (toLower >> (checkExt file ))
let blacklisted (blacklist:string list) (file:string) = blacklist |> List.exists (String.endsWithIgnoreCase file )

let blackList =
[ includeReferences
Expand Down
2 changes: 1 addition & 1 deletion src/Paket.Core/InstallProcess.fs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ let findPackageFolder root (groupName,packageName) (version,settings) =
let targetFolder = getTargetFolder root groupName packageName version includeVersionInPath
let direct = DirectoryInfo targetFolder
if direct.Exists then direct else
match di.GetDirectories() |> Seq.tryFind (fun subDir -> subDir.FullName.ToLower().EndsWith lowerName) with
match di.GetDirectories() |> Seq.tryFind (fun subDir -> String.endsWithIgnoreCase lowerName subDir.FullName) with
| Some x -> x
| None -> failwithf "Package directory for package %O was not found." packageName

Expand Down
12 changes: 6 additions & 6 deletions src/Paket.Core/NuGetV2.fs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ let parseODataDetails(nugetURL,packageName:PackageName,version:SemVerInfo,raw) =
PackageName a.[0],
VersionRequirement.Parse (if a.Length > 1 then a.[1] else "0"),
(if a.Length > 2 && a.[2] <> "" then
if a.[2].ToLower().StartsWith("portable") then [ FrameworkRestriction.Portable(a.[2]) ]
if String.startsWithIgnoreCase "portable" a.[2] then [ FrameworkRestriction.Portable(a.[2]) ]
else
match FrameworkDetection.Extract a.[2] with
| Some x -> [ FrameworkRestriction.Exactly x ]
Expand Down Expand Up @@ -218,7 +218,7 @@ let getDetailsFromNuGetViaOData auth nugetURL (packageName:PackageName) (version
let! raw =
match response with
| Some(r) -> async { return r }
| _ when nugetURL.ToLower().Contains "myget.org" || nugetURL.ToLower().Contains "nuget.org" ->
| _ when String.containsIgnoreCase "myget.org" nugetURL || String.containsIgnoreCase "nuget.org" nugetURL ->
failwithf "Could not get package details for %O from %s" packageName nugetURL
| _ ->
let url = sprintf "%s/odata/Packages(Id='%O',Version='%O')" nugetURL packageName version
Expand Down Expand Up @@ -269,7 +269,7 @@ let findLocalPackage directory (packageName:PackageName) (version:SemVerInfo) =
let v3 =
Directory.EnumerateFiles(directory,"*.nupkg",SearchOption.AllDirectories)
|> Seq.map (fun x -> FileInfo(x))
|> Seq.filter (fun fi -> fi.Name.ToLower().Contains(packageName.GetCompareString()))
|> Seq.filter (fun fi -> String.containsIgnoreCase (packageName.GetCompareString()) fi.Name)
|> Seq.filter (fun fi -> fi.Name.Contains(normalizedVersion) || fi.Name.Contains(version.ToString()))
|> Seq.tryHead

Expand Down Expand Up @@ -434,7 +434,7 @@ let private getFiles targetFolder subFolderName filesDescriptionForVerbose =
let path = Path.Combine(dir.FullName.ToLower(), subFolderName)
if dir.Exists then
dir.GetDirectories()
|> Array.filter (fun fi -> fi.FullName.ToLower() = path)
|> Array.filter (fun fi -> String.equalsIgnoreCase fi.FullName path)
|> Array.collect (fun dir -> dir.GetFiles("*.*", SearchOption.AllDirectories))
else
[||]
Expand Down Expand Up @@ -573,13 +573,13 @@ let GetVersions force root (sources, packageName:PackageName) =
match nugetSource with
| NuGetV2 source ->
let auth = source.Authentication |> Option.map toBasicAuth
if not force && (source.Url.ToLower().Contains "nuget.org" || source.Url.ToLower().Contains "myget.org") then
if not force && (String.containsIgnoreCase "nuget.org" source.Url || String.containsIgnoreCase "myget.org" source.Url) then
[getVersionsCached "Json" tryGetPackageVersionsViaJson (nugetSource, auth, source.Url, packageName) ]
else
let v2Feeds =
[ yield getVersionsCached "OData" tryGetPackageVersionsViaOData (nugetSource, auth, source.Url, packageName)
yield getVersionsCached "ODataWithFilter" tryGetAllVersionsFromNugetODataWithFilter (nugetSource, auth, source.Url, packageName)
if not (source.Url.ToLower().Contains "teamcity" || source.Url.ToLower().Contains "feedservice.svc") then
if not (String.containsIgnoreCase "teamcity" source.Url || String.containsIgnoreCase"feedservice.svc" source.Url ) then
yield getVersionsCached "Json" tryGetPackageVersionsViaJson (nugetSource, auth, source.Url, packageName) ]

match NuGetV3.getAllVersionsAPI(source.Authentication,source.Url) with
Expand Down
7 changes: 4 additions & 3 deletions src/Paket.Core/Nuspec.fs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ module internal NuSpecParserHelper =
| None -> VersionRequirement.Parse "0"
let restriction =
let parent = node.ParentNode
match parent.Name.ToLower(), parent |> getAttribute "targetFramework" with
| "group", Some framework ->
match parent.Name, parent |> getAttribute "targetFramework" with
| name , Some framework
when String.equalsIgnoreCase name "group" ->
match FrameworkDetection.Extract framework with
| Some x -> [FrameworkRestriction.Exactly x]
| None -> []
Expand Down Expand Up @@ -117,7 +118,7 @@ type Nuspec =
| None -> ""
IsDevelopmentDependency =
match doc |> getNode "package" |> optGetNode "metadata" |> optGetNode "developmentDependency" with
| Some link -> link.InnerText.ToLower() = "true"
| Some link -> String.equalsIgnoreCase link.InnerText "true"
| None -> false
FrameworkAssemblyReferences =
let grouped =
Expand Down
2 changes: 1 addition & 1 deletion src/Paket.Core/PackageMetaData.fs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ let findDependencies (dependencies : DependenciesFile) config platform (template
let isSameFileName = (Path.GetFileNameWithoutExtension fi.Name) = name
let isValidExtension =
[".xml"; ".dll"; ".exe"; ".pdb"; ".mdb"]
|> List.exists ((=) (fi.Extension.ToLower()))
|> List.exists (String.equalsIgnoreCase fi.Extension)
isSameFileName && isValidExtension)
)
|> Seq.toArray
Expand Down
2 changes: 1 addition & 1 deletion src/Paket.Core/PackageResolver.fs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ let Resolve(groupName:GroupName, sources, getVersionsF, getPackageDetailsF, stra
let sources = parentSource :: sources |> List.distinct
Seq.singleton (v,sources)
| _ ->
let sources : PackageSource list = sources |> List.sortBy (fun x -> x.Url.ToLower().Contains "nuget.org" |> not)
let sources : PackageSource list = sources |> List.sortBy (fun x -> String.containsIgnoreCase "nuget.org" x.Url |> not)
Seq.singleton (v,sources)

availableVersions :=
Expand Down
2 changes: 1 addition & 1 deletion src/Paket.Core/PackageSources.fs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ type PackageSource =
if uri.Scheme = System.Uri.UriSchemeFile then
LocalNuGet source
else
if source.ToLower().EndsWith("v3/index.json") then
if String.endsWithIgnoreCase "v3/index.json" source then
NuGetV3 { Url = source; Authentication = auth }
else
NuGetV2 { Url = source; Authentication = auth }
Expand Down
25 changes: 13 additions & 12 deletions src/Paket.Core/ProjectFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ module ProjectFile =
try
let fi = FileInfo (normalizePath (projectName.Trim().Trim([|'\"'|]))) // check if we can detect the path
let rec checkDir (dir:DirectoryInfo) =
match projects |> Seq.tryFind (fun p -> (FileInfo p.FileName).Directory.ToString().ToLower() = dir.ToString().ToLower()) with
match projects |> Seq.tryFind (fun p ->
String.equalsIgnoreCase ((FileInfo p.FileName).Directory.ToString()) (dir.ToString())) with
| Some p -> Some p
| None ->
if isNull dir.Parent then None else
Expand Down Expand Up @@ -500,7 +501,7 @@ module ProjectFile =
[for node in project.Document |> getDescendants name do
let isPaketNode = ref false
for child in node.ChildNodes do
if child.Name = "Paket" && child.InnerText.ToLower() = "true" then
if child.Name = "Paket" && String.equalsIgnoreCase child.InnerText "true" then
isPaketNode := true

if !isPaketNode = paketOnes then yield node]
Expand Down Expand Up @@ -777,12 +778,12 @@ module ProjectFile =
propertyNames
|> Seq.concat
|> Seq.distinctBy (fun (x,_,_) -> x)
|> Seq.filter (fun (propertyName,path,buildPath) -> propertyName.ToLower().EndsWith "props")
|> Seq.filter (fun (propertyName,path,buildPath) -> String.endsWithIgnoreCase "props" propertyName)
|> Seq.map (fun (propertyName,path,buildPath) ->
let fileName =
match propertyName.ToLower() with
match propertyName with
| _ when propertyChooseNode.ChildNodes.Count = 0 -> path
| name when name.EndsWith "props" -> sprintf "%s$(%s).props" buildPath propertyName
| name when String.endsWithIgnoreCase name "props" -> sprintf "%s$(%s).props" buildPath propertyName
| _ -> failwithf "Unknown .props filename %s" propertyName

createNode "Import" project
Expand All @@ -795,12 +796,12 @@ module ProjectFile =
propertyNames
|> Seq.concat
|> Seq.distinctBy (fun (x,_,_) -> x)
|> Seq.filter (fun (propertyName,path,buildPath) -> propertyName.ToLower().EndsWith "props" |> not)
|> Seq.filter (fun (propertyName,path,buildPath) -> String.endsWithIgnoreCase "props" propertyName |> not)
|> Seq.map (fun (propertyName,path,buildPath) ->
let fileName =
match propertyName.ToLower() with
match propertyName with
| _ when propertyChooseNode.ChildNodes.Count = 0 -> path
| name when name.EndsWith "targets" ->
| name when String.endsWithIgnoreCase name "targets" ->
sprintf "%s$(%s).targets" buildPath propertyName
| _ -> failwithf "Unknown .targets filename %s" propertyName

Expand Down Expand Up @@ -868,9 +869,9 @@ module ProjectFile =
let i = ref (project.ProjectNode.ChildNodes.Count-1)
while
!i >= 0 &&
(project.ProjectNode.ChildNodes.[!i].OuterXml.ToString().ToLower().StartsWith "<import" &&
project.ProjectNode.ChildNodes.[!i].OuterXml.ToString().ToLower().Contains "label" &&
project.ProjectNode.ChildNodes.[!i].OuterXml.ToString().ToLower().Contains "paket") do
(String.startsWithIgnoreCase (project.ProjectNode.ChildNodes.[!i].OuterXml.ToString()) "<import" &&
String.containsIgnoreCase (project.ProjectNode.ChildNodes.[!i].OuterXml.ToString()) "label" &&
String.containsIgnoreCase (project.ProjectNode.ChildNodes.[!i].OuterXml.ToString()) "paket") do
decr i

if !i <= 0 then
Expand All @@ -882,7 +883,7 @@ module ProjectFile =
project.ProjectNode.InsertAfter(chooseNode,node) |> ignore

let j = ref 0
while !j < project.ProjectNode.ChildNodes.Count && project.ProjectNode.ChildNodes.[!j].OuterXml.ToString().ToLower().StartsWith("<import") do
while !j < project.ProjectNode.ChildNodes.Count && String.startsWithIgnoreCase (project.ProjectNode.ChildNodes.[!j].OuterXml.ToString()) "<import" do
incr j

if propertyChooseNode.ChildNodes.Count > 0 then
Expand Down
2 changes: 1 addition & 1 deletion src/Paket.Core/SolutionFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type SolutionFile(fileName: string) =

member __.RemoveNugetEntries() =
for file in ["nuget.targets"; Constants.PackagesConfigFile; "nuget.exe"; "nuget.config"] do
match content |> Seq.tryFindIndex (fun line -> line.ToLower().Contains(sprintf ".nuget\\%s" file)) with
match content |> Seq.tryFindIndex (fun line -> String.containsIgnoreCase (sprintf ".nuget\\%s" file)line) with
| Some(index) -> content.RemoveAt(index)
| None -> ()

Expand Down
4 changes: 2 additions & 2 deletions src/Paket.Core/TemplateFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ module internal TemplateFile =

let requireLicenseAcceptance =
match get "requireLicenseAcceptance" with
| Some x when x.ToLower() = "true" -> true
| Some x when String.equalsIgnoreCase x "true" -> true
| _ -> false

let tags =
Expand All @@ -333,7 +333,7 @@ module internal TemplateFile =

let developmentDependency =
match get "developmentDependency" with
| Some x when x.ToLower() = "true" -> true
| Some x when String.equalsIgnoreCase x "true" -> true
| _ -> false

let dependencies = getDependencies(fileName,lockFile,map,currentVersion,specificVersions)
Expand Down
13 changes: 13 additions & 0 deletions src/Paket.Core/Utils.fs
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,19 @@ module String =
Some (input.Substring(prefix.Length))
else None

let inline equalsIgnoreCase str1 str2 =
String.Compare(str1,str2,StringComparison.OrdinalIgnoreCase) = 0

let inline containsIgnoreCase (target:string) (text:string) =
text.IndexOf(target, StringComparison.OrdinalIgnoreCase) >= 0


let inline startsWithIgnoreCase (target:string) (text:string) =
text.IndexOf(target, StringComparison.OrdinalIgnoreCase) = 0

let inline endsWithIgnoreCase (target:string) (text:string) =
text.IndexOf(target, StringComparison.OrdinalIgnoreCase) >= text.Length - target.Length

let quoted (text:string) = (if text.Contains(" ") then "\"" + text + "\"" else text)

let inline trim (text:string) = text.Trim()
Expand Down

0 comments on commit d267615

Please sign in to comment.