Skip to content
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
8 changes: 8 additions & 0 deletions src/FSharpLint.Core/Framework/Utilities.fs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ module Dictionary =

module Array =

// Calling Array.collect with an empty array causes it to allocate two empty arrays, which causes significant allocations
// This wrapper short circuits the empty case by directly returning array.empty
let inline collectIfNotEmpty ([<InlineIfLambda>] mapping: 'Source -> 'Dest array) (array: 'Source array) =
if Array.isEmpty array then
Array.empty
else
Array.collect mapping array

let inline mapIfNotEmpty ([<InlineIfLambda>] mapping: 'Source -> 'Dest) (array: 'Source array) =
if Array.isEmpty array then
Array.empty
Expand Down
2 changes: 1 addition & 1 deletion src/FSharpLint.Core/Rules/NamingHelper.fs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ let toAstNodeRule (namingRule:RuleMetadata<NamingRuleConfig>) =

let astNodeRunner (args:AstNodeRuleParams) =
namingRule.RuleConfig.GetIdentifiersToCheck args
|> Array.collect (fun (identifier, idText, typeCheck) ->
|> Array.collectIfNotEmpty (fun (identifier, idText, typeCheck) ->
let suggestions = checkIdentifier namingRule.RuleConfig.Config identifier idText
Array.map (fun suggestion -> { suggestion with TypeChecks = Option.toList typeCheck }) suggestions)

Expand Down
Loading