Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minor cleanup: Removed double-dictionary lookups #3620

Merged
merged 1 commit into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Fable.Build/GithubRelease.fs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ let handle (args: string list) =
let githubToken =
Environment.GetEnvironmentVariable("GITHUB_TOKEN_FABLE_ORG")

if githubToken = null then
if isNull githubToken then
failwith "Missing GITHUB_TOKEN_FABLE_ORG environment variable"

let versionInfo = Changelog.getLastVersion Changelog.fableCLi
Expand Down
2 changes: 1 addition & 1 deletion src/Fable.Build/Publish.fs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ let private publishNuget (fsprojDir: string) =

let nugetKey = Environment.GetEnvironmentVariable("FABLE_NUGET_KEY")

if nugetKey = null then
if isNull nugetKey then
failwithf $"Missing FABLE_NUGET_KEY environment variable"

if Fsproj.needPublishing fsprojContent lastVersion then
Expand Down
40 changes: 24 additions & 16 deletions src/Fable.Build/Utils/ChangelogParser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -71,30 +71,35 @@ module Types =
[<RequireQualifiedAccess>]
module Lexer =

[<return: Struct>]
let private (|Match|_|) pattern input =
let m = Regex.Match(input, pattern)

if m.Success then
Some m
ValueSome m
else
None
ValueNone

[<return: Struct>]
let private (|Title|_|) (input: string) =
match input with
| Match "^# ?[^#]" _ -> input.Substring(1).Trim() |> Some
| _ -> None
| Match "^# ?[^#]" _ -> input.Substring(1).Trim() |> ValueSome
| _ -> ValueNone

[<return: Struct>]
let private (|Semver|_|) (input: string) =
match input with
| Match "\\[?v?([\\w\\d.-]+\\.[\\w\\d.-]+[a-zA-Z0-9])\\]?" m ->
Some m.Groups.[1].Value
| _ -> None
ValueSome m.Groups.[1].Value
| _ -> ValueNone

[<return: Struct>]
let private (|Date|_|) (input: string) =
match input with
| Match "(\\d{4}-\\d{2}-\\d{2})" m -> Some m.Groups.[0].Value
| _ -> None
| Match "(\\d{4}-\\d{2}-\\d{2})" m -> ValueSome m.Groups.[0].Value
| _ -> ValueNone

[<return: Struct>]
let private (|Version|_|) (input: string) =
match input with
| Match "^##? ?[^#]" _ ->
Expand All @@ -110,24 +115,27 @@ module Lexer =

let title = input.Substring(2).Trim()

Some(title, version, date)
ValueSome(title, version, date)

| _ -> None
| _ -> ValueNone

[<return: Struct>]
let private (|SubSection|_|) (input: string) =
match input with
| Match "^### ?[^#]" _ -> input.Substring(3).Trim() |> Some
| _ -> None
| Match "^### ?[^#]" _ -> input.Substring(3).Trim() |> ValueSome
| _ -> ValueNone

[<return: Struct>]
let private (|SubSubSection|_|) (input: string) =
match input with
| Match "^#### ?[^#]" _ -> input.Substring(4).Trim() |> Some
| _ -> None
| Match "^#### ?[^#]" _ -> input.Substring(4).Trim() |> ValueSome
| _ -> ValueNone

[<return: Struct>]
let private (|ListItem|_|) (input: string) =
match input with
| Match "^[*-]" _ -> input.Substring(1).Trim() |> Some
| _ -> None
| Match "^[*-]" _ -> input.Substring(1).Trim() |> ValueSome
| _ -> ValueNone

let toSymbols (lines: string list) =
lines
Expand Down
7 changes: 3 additions & 4 deletions src/Fable.Cli/FileWatchers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,9 @@ type PollingFileWatcher(watchedDirectoryPath, ignoredDirectoryNameRegexes) =
(fun f ->
let fullFilePath = f.FullName

if not <| knownEntities.ContainsKey(fullFilePath) then
recordChange f // New file
else
let fileMeta = knownEntities.[fullFilePath]
match knownEntities.TryGetValue fullFilePath with
| false, _ -> recordChange f // New file
| true, fileMeta ->

try
if
Expand Down
6 changes: 3 additions & 3 deletions src/Fable.Transforms/FSharp2Fable.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3234,9 +3234,9 @@ type FableCompiler(com: Compiler) =
let onlyOnceWarnings = HashSet<string>()

member _.ReplaceAttachedMembers(entityFullName, f) =
if attachedMembers.ContainsKey(entityFullName) then
attachedMembers[entityFullName] <- f attachedMembers[entityFullName]
else
match attachedMembers.TryGetValue entityFullName with
| true, members -> attachedMembers[entityFullName] <- f members
| false, _ ->
let members =
{|
NonMangledNames = HashSet()
Expand Down
8 changes: 4 additions & 4 deletions src/Fable.Transforms/Php/Fable2Php.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1920,7 +1920,7 @@ and findCasesNames evalExpr tree =

and hasGroupedCases indices tree =
match tree with
| Fable.IfThenElse(Fable.Test(_, _, _),
| Fable.IfThenElse(Fable.Test(_),
Fable.DecisionTreeSuccess(index, _, _),
elseExpr,
_) ->
Expand All @@ -1933,18 +1933,18 @@ and hasGroupedCases indices tree =
true
else
false
| Fable.IfThenElse(Fable.Test(_, _, _), _, _, _) -> false
| Fable.IfThenElse(Fable.Test(_), _, _, _) -> false
| _ -> failwithf "Invalid Condition AST"

and getCases cases tree =
match tree with
| Fable.IfThenElse(Fable.Test(_, _, _),
| Fable.IfThenElse(Fable.Test(_),
Fable.DecisionTreeSuccess(index, boundValues, _),
elseExpr,
_) -> getCases (Map.add index boundValues cases) elseExpr
| Fable.DecisionTreeSuccess(index, boundValues, _) ->
Map.add index boundValues cases
| Fable.IfThenElse(Fable.Test(_, _, _), _, _, _) -> cases
| Fable.IfThenElse(Fable.Test(_), _, _, _) -> cases
| _ -> failwithf "Invalid Condition AST"


Expand Down
2 changes: 1 addition & 1 deletion src/Fable.Transforms/Python/Replacements.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2193,7 +2193,7 @@ let operators
?loc = r
)
|> Some
| ExprType(Number(_, _)) :: _ ->
| ExprType(Number(_)) :: _ ->
Helper.LibCall(
com,
"long",
Expand Down
4 changes: 2 additions & 2 deletions src/Fable.Transforms/Replacements.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2702,7 +2702,7 @@ let stringModule
| "Length", [ arg ] -> getFieldWith r t arg "length" |> Some
| ("Iterate" | "IterateIndexed" | "ForAll" | "Exists"), _ ->
// Cast the string to char[], see #1279
let args = args |> List.replaceLast (fun e -> stringToCharArray e)
let args = args |> List.replaceLast stringToCharArray

Helper.LibCall(
com,
Expand All @@ -2717,7 +2717,7 @@ let stringModule
|> Some
| ("Map" | "MapIndexed" | "Collect"), _ ->
// Cast the string to char[], see #1279
let args = args |> List.replaceLast (fun e -> stringToCharArray e)
let args = args |> List.replaceLast stringToCharArray
let name = Naming.lowerFirst i.CompiledName

emitExpr
Expand Down
2 changes: 1 addition & 1 deletion src/Fable.Transforms/Rust/AST/Rust.AST.Impl.fs
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ type VariantData with
/// Return the `NodeId` of this variant's constructor, if it has one.
member self.ctor_id() : Option<NodeId> =
match self with
| VariantData.Struct(_, _) -> None
| VariantData.Struct(_) -> None
| VariantData.Tuple(_, id)
| VariantData.Unit(id) -> Some(id)

Expand Down
6 changes: 1 addition & 5 deletions src/Fable.Transforms/State.fs
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,7 @@ type Project
=

let inlineExprsDic =
implFiles
|> Map.values
|> Seq.map (fun f -> f.InlineExprs)
|> Seq.concat
|> dict
implFiles |> Map.values |> Seq.collect (fun f -> f.InlineExprs) |> dict

let precompiledInfo =
precompiledInfo
Expand Down
6 changes: 3 additions & 3 deletions src/fable-library-dart/Seq2.fs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ let countBy
for x in xs do
let key = projection x

if dict.ContainsKey(key) then
dict[key] <- dict[key] + 1
else
match dict.TryGetValue key with
| true, v -> dict[key] <- v + 1
| false, _ ->
dict[key] <- 1
keys.Add(key)

Expand Down
2 changes: 1 addition & 1 deletion src/fable-library-dart/Set.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1041,7 +1041,7 @@ let union (set1: Set<'T>) (set2: Set<'T>) = set1 + set2

// [<CompiledName("UnionMany")>]
let unionMany (sets: seq<Set<'T>>) ([<Inject>] comparer: IComparer<'T>) =
Seq.fold (fun s1 s2 -> s1 + s2) (Set<'T>.Empty comparer) sets
Seq.fold (+) (Set<'T>.Empty comparer) sets

// [<CompiledName("Intersect")>]
let intersect (set1: Set<'T>) (set2: Set<'T>) = Set<'T>.Intersection(set1, set2)
Expand Down
2 changes: 1 addition & 1 deletion src/fable-library/Array.fs
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ let fold<'T, 'State> folder (state: 'State) (array: 'T[]) =
// acc <- folder acc array.[i]
// acc
// else
foldImpl (fun acc x -> folder acc x) state array
foldImpl folder state array

let iterate action (array: 'T[]) =
for i = 0 to array.Length - 1 do
Expand Down
2 changes: 1 addition & 1 deletion src/fable-library/Set.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1071,7 +1071,7 @@ let union (set1: Set<'T>) (set2: Set<'T>) = set1 + set2

// [<CompiledName("UnionMany")>]
let unionMany (sets: seq<Set<'T>>) ([<Inject>] comparer: IComparer<'T>) =
Seq.fold (fun s1 s2 -> s1 + s2) (Set<'T>.Empty comparer) sets
Seq.fold (+) (Set<'T>.Empty comparer) sets

// [<CompiledName("Intersect")>]
let intersect (set1: Set<'T>) (set2: Set<'T>) = Set<'T>.Intersection(set1, set2)
Expand Down
Loading