Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit67ef2fb

Browse files
Merge pull request#71013 from CyrusNajmabadi/useSingleInit
Use new helper type for initializing a value type field only once, and in a threadsafe manner.
2 parents0caa9d1 +f2b36d2 commit67ef2fb

File tree

4 files changed

+14
-35
lines changed

4 files changed

+14
-35
lines changed

‎src/Compilers/CSharp/Portable/Compilation/BuiltInOperators.cs‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ internal class BuiltInOperators
2727
//actual lazily-constructed caches of built-in operators.
2828
privateImmutableArray<UnaryOperatorSignature>[]_builtInUnaryOperators;
2929
privateImmutableArray<BinaryOperatorSignature>[][]_builtInOperators;
30-
privateStrongBox<BinaryOperatorSignature>_builtInUtf8Concatenation;
30+
privateSingleInitNullable<BinaryOperatorSignature>_builtInUtf8Concatenation;
3131

3232
internalBuiltInOperators(CSharpCompilationcompilation)
3333
{
@@ -692,14 +692,11 @@ internal void GetUtf8ConcatenationBuiltInOperator(TypeSymbol readonlySpanOfByte,
692692
Debug.Assert(_compilation.IsReadOnlySpanType(readonlySpanOfByte));
693693
Debug.Assert(((NamedTypeSymbol)readonlySpanOfByte).TypeArgumentsWithAnnotationsNoUseSiteDiagnostics.Single().Type.SpecialTypeisSpecialType.System_Byte);
694694

695-
if(_builtInUtf8Concatenationisnull)
696-
{
697-
Interlocked.CompareExchange(ref_builtInUtf8Concatenation,
698-
newStrongBox<BinaryOperatorSignature>(
699-
newBinaryOperatorSignature(BinaryOperatorKind.Utf8Addition,readonlySpanOfByte,readonlySpanOfByte,readonlySpanOfByte)),null);
700-
}
695+
varutfConcatenation=_builtInUtf8Concatenation.Initialize(
696+
static readonlySpanOfByte=>newBinaryOperatorSignature(BinaryOperatorKind.Utf8Addition,readonlySpanOfByte,readonlySpanOfByte,readonlySpanOfByte),
697+
readonlySpanOfByte);
701698

702-
operators.Add(_builtInUtf8Concatenation.Value);
699+
operators.Add(utfConcatenation);
703700
}
704701

705702
internalBinaryOperatorSignatureGetSignature(BinaryOperatorKindkind)

‎src/Compilers/CSharp/Portable/Syntax/CSharpSyntaxTree.cs‎

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -711,17 +711,8 @@ internal PragmaWarningState GetPragmaDirectiveWarningState(string id, int positi
711711
}
712712

713713
privateNullableContextStateMapGetNullableContextStateMap()
714-
{
715-
if(_lazyNullableContextStateMap==null)
716-
{
717-
// Create the #nullable directive map on demand.
718-
Interlocked.CompareExchange(
719-
ref_lazyNullableContextStateMap,
720-
newStrongBox<NullableContextStateMap>(NullableContextStateMap.Create(this)),
721-
null);
722-
}
723-
return_lazyNullableContextStateMap.Value;
724-
}
714+
// Create the #nullable directive map on demand.
715+
=>_lazyNullableContextStateMap.Initialize(static @this=>NullableContextStateMap.Create(@this),this);
725716

726717
internalNullableContextStateGetNullableContextState(intposition)
727718
=>GetNullableContextStateMap().GetContextState(position);
@@ -754,7 +745,7 @@ bool isGeneratedHeuristic()
754745

755746
privateCSharpLineDirectiveMap?_lazyLineDirectiveMap;
756747
privateCSharpPragmaWarningStateMap?_lazyPragmaWarningStateMap;
757-
privateStrongBox<NullableContextStateMap>?_lazyNullableContextStateMap;
748+
privateSingleInitNullable<NullableContextStateMap>_lazyNullableContextStateMap;
758749

759750
privateGeneratedKind_lazyIsGeneratedCode=GeneratedKind.Unknown;
760751

‎src/Compilers/Core/Portable/CommandLine/AnalyzerConfigSet.cs‎

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public sealed class AnalyzerConfigSet
5959

6060
privatereadonlyObjectPool<List<Section>>_sectionKeyPool=newObjectPool<List<Section>>(()=>newList<Section>());
6161

62-
privateStrongBox<AnalyzerConfigOptionsResult>?_lazyConfigOptions;
62+
privateSingleInitNullable<AnalyzerConfigOptionsResult>_lazyConfigOptions;
6363

6464
privatesealedclassSequenceEqualComparer:IEqualityComparer<List<Section>>
6565
{
@@ -166,20 +166,7 @@ private AnalyzerConfigSet(ImmutableArray<AnalyzerConfig> analyzerConfigs, Global
166166
/// Gets an <see cref="AnalyzerConfigOptionsResult"/> that contain the options that apply globally
167167
/// </summary>
168168
publicAnalyzerConfigOptionsResultGlobalConfigOptions
169-
{
170-
get
171-
{
172-
if(_lazyConfigOptionsisnull)
173-
{
174-
Interlocked.CompareExchange(
175-
ref_lazyConfigOptions,
176-
newStrongBox<AnalyzerConfigOptionsResult>(ParseGlobalConfigOptions()),
177-
null);
178-
}
179-
180-
return_lazyConfigOptions.Value;
181-
}
182-
}
169+
=>_lazyConfigOptions.Initialize(static @this=>@this.ParseGlobalConfigOptions(),this);
183170

184171
/// <summary>
185172
/// Returns a <see cref="AnalyzerConfigOptionsResult"/> for a source file. This computes which <see cref="AnalyzerConfig"/> rules applies to this file, and correctly applies

‎src/Compilers/Core/Portable/DiagnosticAnalyzer/SuppressMessageAttributeState.cs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ private static bool TryGetTargetScope(SuppressMessageInfo info, out TargetScope
3434
privatereadonlyCompilation_compilation;
3535
privateGlobalSuppressions?_lazyGlobalSuppressions;
3636
privatereadonlyConcurrentDictionary<ISymbol,ImmutableDictionary<string,SuppressMessageInfo>>_localSuppressionsBySymbol;
37+
38+
// These are StrongBoxes because 'null' is a valid symbol value to compute for these, and as such, we can't use
39+
// the null value to indicate 'not yet computed'.
40+
3741
privateStrongBox<ISymbol?>?_lazySuppressMessageAttribute;
3842
privateStrongBox<ISymbol?>?_lazyUnconditionalSuppressMessageAttribute;
3943

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp