8000 Add one more comment for clarity · dotnet/wpf@0a4cc57 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0a4cc57

Browse files
committed
Add one more comment for clarity
1 parent 99b9573 commit 0a4cc57

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/XamlNamespace.cs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ internal class XamlNamespace
1515
{
1616
public readonly XamlSchemaContext SchemaContext;
1717

18-
private List<AssemblyNamespacePair> _assemblyNamespaces;
18+
private AssemblyNamespacePair[] _assemblyNamespaces;
1919
private ConcurrentDictionary<string, XamlType> _typeCache;
2020
private ICollection<XamlType> _allPublicTypes;
2121

@@ -169,15 +169,15 @@ internal int RevisionNumber
169169
{
170170
// The only external mutation we allow is adding new namespaces. So the count of
171171
// namespaces also serves as a revision number.
172-
get => (_assemblyNamespaces is not null) ? _assemblyNamespaces.Count : 0;
172+
get => (_assemblyNamespaces != null) ? _assemblyNamespaces.Length : 0;
173173
}
174174

175175
private Type TryGetType(string typeName)
176176
{
177177
Type type = SearchAssembliesForShortName(typeName);
178178
if (type is null && IsClrNamespace)
179179
{
180-
Debug.Assert(_assemblyNamespaces.Count == 1);
180+
Debug.Assert(_assemblyNamespaces.Length == 1);
181181
type = XamlLanguage.LookupClrNamespaceType(_assemblyNamespaces[0], typeName);
182182
}
183183

@@ -233,13 +233,13 @@ private ICollection<XamlType> LookupAllTypes()
233233
return xamlTypeList.AsReadOnly();
234234
}
235235

236-
private List<AssemblyNamespacePair> GetClrNamespacePair(string clrNs, string assemblyName)
236+
private AssemblyNamespacePair[] GetClrNamespacePair(string clrNs, string assemblyName)
237237
{
238238
Assembly asm = SchemaContext.OnAssemblyResolve(assemblyName);
239239
if (asm is null)
240240
return null;
241241

242-
return new List<AssemblyNamespacePair>(1) { new AssemblyNamespacePair(asm, clrNs) };
242+
return new AssemblyNamespacePair[1] { new AssemblyNamespacePair(asm, clrNs) };
243243
}
244244

245245
private Type SearchAssembliesForShortName(string shortName)
@@ -268,22 +268,23 @@ private Type SearchAssembliesForShortName(string shortName)
268268
// This method should only be called inside SchemaContext._syncExaminingAssemblies lock
269269
internal void AddAssemblyNamespacePair(AssemblyNamespacePair pair)
270270
{
271-
// To allow the list to be read by multiple threads, we create a new list, add the pair,
272-
// then assign it back to the original variable. Assignments are assured to be atomic.
271+
// To allow the array to be read concurrently by multiple threads, we create a new array, add the pair,
272+
// then assign it back to the original variable. Assignments are guaranteed to be atomic for word size.
273273

274-
List<AssemblyNamespacePair> assemblyNamespacesCopy;
274+
AssemblyNamespacePair[] assemblyNamespacesCopy;
275275
if (_assemblyNamespaces is null)
276276
{
277-
assemblyNamespacesCopy = new List<AssemblyNamespacePair>(1);
277+
assemblyNamespacesCopy = new AssemblyNamespacePair[1];
278278
Initialize();
279279
}
280280
else
281281
{
282-
assemblyNamespacesCopy = new List<AssemblyNamespacePair>(_assemblyNamespaces.Count + 1);
282+
assemblyNamespacesCopy = new AssemblyNamespacePair[_assemblyNamespaces.Length + 1];
283283
}
284284

285-
assemblyNamespacesCopy.AddRange(_assemblyNamespaces);
286-
assemblyNamespacesCopy.Add(pair);
285+
// Copy over and add new item
286+
_assemblyNamespaces.CopyTo(assemblyNamespacesCopy, 0);
287+
assemblyNamespacesCopy[assemblyNamespacesCopy.Length - 1] = pair;
287288

288289
_assemblyNamespaces = assemblyNamespacesCopy;
289290
}

src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlSchemaContext.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,6 +1181,7 @@ private bool UpdateXmlNsInfo(XmlNsInfo nsInfo)
11811181
return foundNew;
11821182
}
11831183

1184+
// This method should be called inside _syncExaminingAssemblies lock
11841185
private bool UpdateNamespaceByUriList(XmlNsInfo nsInfo)
11851186
{
11861187
IList<XmlNsInfo.XmlNsDefinition> xmlnsDefs = nsInfo.NsDefs;

0 commit comments

Comments
 (0)
0