File tree Expand file tree Collapse file tree 2 files changed +6
-11
lines changed Expand file tree Collapse file tree 2 files changed +6
-11
lines changed Original file line number Diff line number Diff line change @@ -57,10 +57,8 @@ module internal Adapters =
57
57
System.Threading.Monitor.Exit( d)
58
58
59
59
#else
60
- let d = new System.Collections.Concurrent.ConcurrentDictionary< Type,_>( HashIdentity.Structural)
61
- fun x ->
62
- let mutable res = Unchecked.defaultof<_>
63
- if d.TryGetValue( x ,& res) then res else let res = f x in d.[ x] <- res; res
60
+ let d = new System.Collections.Concurrent.ConcurrentDictionary< Type, 'b>( HashIdentity.Structural)
61
+ fun x -> d.GetOrAdd( x, fun r -> f r)
64
62
#endif
65
63
66
64
let isPartiallyImmutableRecord : Type -> bool =
Original file line number Diff line number Diff line change @@ -152,13 +152,11 @@ module internal Microsoft.FSharp.Compiler.PrettyNaming
152
152
153
153
/// Memoize compilation of custom operators.
154
154
/// They're typically used more than once so this avoids some CPU and GC overhead.
155
- let compiledOperators = ConcurrentDictionary<_,_ > ( System.StringComparer.Ordinal)
155
+ let compiledOperators = ConcurrentDictionary<_, string > ( System.StringComparer.Ordinal)
156
156
157
- fun op ->
157
+ fun opp ->
158
158
// Has this operator already been compiled?
159
- match compiledOperators.TryGetValue op with
160
- | true , opName -> opName
161
- | false , _ ->
159
+ compiledOperators.GetOrAdd( opp, fun ( op : string ) ->
162
160
let opLength = op.Length
163
161
let sb = new System.Text.StringBuilder ( opNamePrefix, opNamePrefix.Length + ( opLength * maxOperatorNameLength))
164
162
for i = 0 to opLength - 1 do
@@ -173,8 +171,7 @@ module internal Microsoft.FSharp.Compiler.PrettyNaming
173
171
let opName = sb.ToString ()
174
172
175
173
// Cache the compiled name so it can be reused.
176
- compiledOperators.TryAdd ( op, opName) |> ignore
177
- opName
174
+ opName)
178
175
179
176
// +++ GLOBAL STATE
180
177
/// Compiles an operator into a mangled operator name.
You can’t perform that action at this time.
0 commit comments