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
6 changes: 2 additions & 4 deletions src/fsharp/FSharp.Core/QueryExtensions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,8 @@ module internal Adapters =
System.Threading.Monitor.Exit(d)

#else
let d = new System.Collections.Concurrent.ConcurrentDictionary<Type,_>(HashIdentity.Structural)
fun x ->
let mutable res = Unchecked.defaultof<_>
if d.TryGetValue(x ,&res) then res else let res = f x in d.[x] <- res; res
let d = new System.Collections.Concurrent.ConcurrentDictionary<Type,'b>(HashIdentity.Structural)
fun x -> d.GetOrAdd(x, fun r -> f r)
#endif

let isPartiallyImmutableRecord : Type -> bool =
Expand Down
11 changes: 4 additions & 7 deletions src/fsharp/PrettyNaming.fs
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,11 @@ module internal Microsoft.FSharp.Compiler.PrettyNaming

/// Memoize compilation of custom operators.
/// They're typically used more than once so this avoids some CPU and GC overhead.
let compiledOperators = ConcurrentDictionary<_,_> (System.StringComparer.Ordinal)
let compiledOperators = ConcurrentDictionary<_,string> (System.StringComparer.Ordinal)

fun op ->
fun opp ->
// Has this operator already been compiled?
match compiledOperators.TryGetValue op with
| true, opName -> opName
| false, _ ->
compiledOperators.GetOrAdd(opp, fun (op:string) ->
let opLength = op.Length
let sb = new System.Text.StringBuilder (opNamePrefix, opNamePrefix.Length + (opLength * maxOperatorNameLength))
for i = 0 to opLength - 1 do
Expand All @@ -173,8 +171,7 @@ module internal Microsoft.FSharp.Compiler.PrettyNaming
let opName = sb.ToString ()

// Cache the compiled name so it can be reused.
compiledOperators.TryAdd (op, opName) |> ignore
opName
opName)

// +++ GLOBAL STATE
/// Compiles an operator into a mangled operator name.
Expand Down