@@ -20,8 +20,8 @@ private HierarchyIdMap() { }
2020 /// </summary>
2121 public uint Add ( HierarchyNode node )
2222 {
23- Debug . Assert ( VisualStudio . Shell . ThreadHelper . CheckAccess ( ) ) ;
24-
23+ VisualStudio . Shell . ThreadHelper . ThrowIfNotOnUIThread ( ) ;
24+ Debug . Assert ( node != null , "The node added here should never be null." ) ;
2525#if DEBUG
2626 foreach ( var reference in this . nodes . Values )
2727 {
@@ -33,7 +33,6 @@ public uint Add(HierarchyNode node)
3333 }
3434 }
3535 }
36-
3736#endif
3837 if ( ! this . freedIds . TryPop ( out var idx ) )
3938 {
@@ -48,16 +47,16 @@ public uint Add(HierarchyNode node)
4847
4948 private uint NextIndex ( )
5049 {
50+ // +1 since 0 is not a valid HierarchyId
5151 return ( uint ) this . nodes . Count + 1 ;
5252 }
5353
54-
5554 /// <summary>
5655 /// Must be called from the UI thread
5756 /// </summary>
5857 public void Remove ( HierarchyNode node )
5958 {
60- Debug . Assert ( VisualStudio . Shell . ThreadHelper . CheckAccess ( ) ) ;
59+ VisualStudio . Shell . ThreadHelper . ThrowIfNotOnUIThread ( ) ;
6160
6261 Debug . Assert ( node != null , "Called with null node" ) ;
6362
@@ -66,7 +65,7 @@ public void Remove(HierarchyNode node)
6665 var removeCheck = this . nodes . TryRemove ( idx , out var weakRef ) ;
6766
6867 Debug . Assert ( removeCheck , "How did we get an id, which we haven't seen before" ) ;
69- Debug . Assert ( weakRef != null , "Double delete is not expected ." ) ;
68+ Debug . Assert ( weakRef != null , "How did we insert a null value ." ) ;
7069 Debug . Assert ( weakRef . TryGetTarget ( out var found ) && object . ReferenceEquals ( node , found ) , "The node has the wrong id, or was GC-ed before." ) ;
7170
7271 this . freedIds . Push ( idx ) ;
@@ -79,7 +78,7 @@ public HierarchyNode this[uint itemId]
7978 {
8079 get
8180 {
82- Debug . Assert ( VisualStudio . Shell . ThreadHelper . CheckAccess ( ) ) ;
81+ VisualStudio . Shell . ThreadHelper . ThrowIfNotOnUIThread ( ) ;
8382
8483 var idx = itemId ;
8584 if ( this . nodes . TryGetValue ( idx , out var reference ) && reference != null && reference . TryGetTarget ( out var node ) )
0 commit comments