@@ -39,15 +39,15 @@ public UpaException(object? particle1, object? particle2)
39
39
internal sealed class SymbolsDictionary
40
40
{
41
41
private int _last ;
42
- private readonly Hashtable _names ;
43
- private Hashtable ? _wildcards ;
42
+ private readonly Dictionary < XmlQualifiedName , int > _names ;
43
+ private Dictionary < string , int > ? _wildcards ;
44
44
private readonly ArrayList _particles ;
45
45
private object ? _particleLast ;
46
46
private bool _isUpaEnforced = true ;
47
47
48
48
public SymbolsDictionary ( )
49
49
{
50
- _names = new Hashtable ( ) ;
50
+ _names = new Dictionary < XmlQualifiedName , int > ( ) ;
51
51
_particles = new ArrayList ( ) ;
52
52
}
53
53
@@ -71,10 +71,8 @@ public bool IsUpaEnforced
71
71
/// </summary>
72
72
public int AddName ( XmlQualifiedName name , object ? particle )
73
73
{
74
- object ? lookup = _names [ name ] ;
75
- if ( lookup != null )
74
+ if ( _names . TryGetValue ( name , out int symbol ) )
76
75
{
77
- int symbol = ( int ) lookup ;
78
76
if ( _particles [ symbol ] != particle )
79
77
{
80
78
_isUpaEnforced = false ;
@@ -116,13 +114,9 @@ public void AddNamespaceList(NamespaceList list, object particle, bool allowLoca
116
114
117
115
private void AddWildcard ( string wildcard , object ? particle )
118
116
{
119
- if ( _wildcards == null )
120
- {
121
- _wildcards = new Hashtable ( ) ;
122
- }
117
+ _wildcards ??= new Dictionary < string , int > ( ) ;
123
118
124
- object ? lookup = _wildcards [ wildcard ] ;
125
- if ( lookup == null )
119
+ if ( ! _wildcards . TryGetValue ( wildcard , out int lookup ) )
126
120
{
127
121
_wildcards . Add ( wildcard , _last ) ;
128
122
_particles . Add ( particle ) ;
@@ -131,15 +125,16 @@ private void AddWildcard(string wildcard, object? particle)
131
125
}
132
126
else if ( particle != null )
133
127
{
134
- _particles [ ( int ) lookup ] = particle ;
128
+ _particles [ lookup ] = particle ;
135
129
}
136
130
}
137
131
138
132
public ICollection GetNamespaceListSymbols ( NamespaceList list )
139
133
{
140
134
ArrayList match = new ArrayList ( ) ;
141
- foreach ( XmlQualifiedName ? name in _names . Keys )
135
+ foreach ( KeyValuePair < XmlQualifiedName , int > entry in _names )
142
136
{
137
+ XmlQualifiedName name = entry . Key ;
143
138
Debug . Assert ( name != null ) ;
144
139
if ( name != XmlQualifiedName . Empty && list . Allows ( name ) )
145
140
{
@@ -149,11 +144,11 @@ public ICollection GetNamespaceListSymbols(NamespaceList list)
149
144
150
145
if ( _wildcards != null )
151
146
{
152
- foreach ( string wildcard in _wildcards . Keys )
147
+ foreach ( KeyValuePair < string , int > wildcard in _wildcards )
153
148
{
154
- if ( list . Allows ( wildcard ) )
149
+ if ( list . Allows ( wildcard . Key ) )
155
150
{
156
- match . Add ( _wildcards [ wildcard ] ) ;
151
+ match . Add ( wildcard . Value ) ;
157
152
}
158
153
}
159
154
}
@@ -173,19 +168,14 @@ public int this[XmlQualifiedName name]
173
168
{
174
169
get
175
170
{
176
- object ? lookup = _names [ name ] ;
177
- if ( lookup != null )
171
+ if ( _names . TryGetValue ( name , out int symbol ) )
178
172
{
179
- return ( int ) lookup ;
173
+ return symbol ;
180
174
}
181
175
182
- if ( _wildcards != null )
176
+ if ( _wildcards != null && _wildcards . TryGetValue ( name . Namespace , out int lookup ) )
183
177
{
184
- lookup = _wildcards [ name . Namespace ] ;
185
- if ( lookup != null )
186
- {
187
- return ( int ) lookup ;
188
- }
178
+ return lookup ;
189
179
}
190
180
191
181
return _last ; // true wildcard
@@ -195,16 +185,7 @@ public int this[XmlQualifiedName name]
195
185
/// <summary>
196
186
/// Check if a name exists in the symbol dictionary
197
187
/// </summary>
198
- public bool Exists ( XmlQualifiedName name )
199
- {
200
- object ? lookup = _names [ name ] ;
201
- if ( lookup != null )
202
- {
203
- return true ;
204
- }
205
-
206
- return false ;
207
- }
188
+ public bool Exists ( XmlQualifiedName name ) => _names . ContainsKey ( name ) ;
208
189
209
190
/// <summary>
210
191
/// Return content processing mode for the symbol
@@ -219,21 +200,21 @@ public bool Exists(XmlQualifiedName name)
219
200
/// </summary>
220
201
public string NameOf ( int symbol )
221
202
{
222
- foreach ( DictionaryEntry de in _names )
203
+ foreach ( KeyValuePair < XmlQualifiedName , int > name in _names )
223
204
{
224
- if ( ( int ) de . Value ! == symbol )
205
+ if ( name . Value == symbol )
225
206
{
226
- return ( ( XmlQualifiedName ) de . Key ) . ToString ( ) ;
207
+ return name . Key . ToString ( ) ;
227
208
}
228
209
}
229
210
230
211
if ( _wildcards != null )
231
212
{
232
- foreach ( DictionaryEntry de in _wildcards )
213
+ foreach ( KeyValuePair < string , int > wildcard in _wildcards )
233
214
{
234
- if ( ( int ) de ! . Value ! == symbol )
215
+ if ( wildcard . Value == symbol )
235
216
{
236
- return $ "{ ( string ) de . Key } :*";
217
+ return $ "{ wildcard . Key } :*";
237
218
}
238
219
}
239
220
}
@@ -1467,7 +1448,7 @@ private void CheckUniqueParticleAttribution(BitSet curpos)
1467
1448
ArrayList transitionTable = new ArrayList ( ) ;
1468
1449
1469
1450
// state lookup table (Dstate in the book)
1470
- Hashtable stateTable = new Hashtable ( ) ;
1451
+ Dictionary < BitSet , int > stateTable = new ( ) ;
1471
1452
1472
1453
// Add empty set that would signal an error
1473
1454
stateTable . Add ( new BitSet ( positionsCount ) , - 1 ) ;
@@ -1485,7 +1466,7 @@ private void CheckUniqueParticleAttribution(BitSet curpos)
1485
1466
while ( unmarked . Count > 0 )
1486
1467
{
1487
1468
BitSet statePosSet = unmarked . Dequeue ( ) ; // all positions that constitute DFA state
1488
- Debug . Assert ( state == ( int ) stateTable [ statePosSet ] ! ) ; // just make sure that statePosSet is for correct state
1469
+ Debug . Assert ( state == stateTable [ statePosSet ] ) ; // just make sure that statePosSet is for correct state
1489
1470
int [ ] transition = ( int [ ] ) transitionTable [ state ] ! ;
1490
1471
if ( statePosSet [ endMarkerPos ] )
1491
1472
{
@@ -1509,10 +1490,9 @@ private void CheckUniqueParticleAttribution(BitSet curpos)
1509
1490
1510
1491
// if U is not empty and is not in Dstates then
1511
1492
// add U as an unmarked state to Dstates
1512
- object ? lookup = stateTable [ newset ] ;
1513
- if ( lookup != null )
1493
+ if ( stateTable . TryGetValue ( newset , out int lookup ) )
1514
1494
{
1515
- transition [ symbol ] = ( int ) lookup ;
1495
+ transition [ symbol ] = lookup ;
1516
1496
}
1517
1497
else
1518
1498
{
@@ -2151,33 +2131,33 @@ public override ArrayList ExpectedParticles(ValidationState context, bool isRequ
2151
2131
2152
2132
internal sealed class AllElementsContentValidator : ContentValidator
2153
2133
{
2154
- private readonly Hashtable _elements ; // unique terminal names to positions in Bitset mapping
2134
+ private readonly Dictionary < XmlQualifiedName , int > _elements ; // unique terminal names to positions in Bitset mapping
2155
2135
private readonly object [ ] _particles ;
2156
2136
private readonly BitSet _isRequired ; // required flags
2157
2137
private int _countRequired ;
2158
2138
2159
2139
public AllElementsContentValidator ( XmlSchemaContentType contentType , int size , bool isEmptiable ) : base ( contentType , false , isEmptiable )
2160
2140
{
2161
- _elements = new Hashtable ( size ) ;
2141
+ _elements = new Dictionary < XmlQualifiedName , int > ( size ) ;
2162
2142
_particles = new object [ size ] ;
2163
2143
_isRequired = new BitSet ( size ) ;
2164
2144
}
2165
2145
2166
2146
public bool AddElement ( XmlQualifiedName name , object particle , bool isEmptiable )
2167
2147
{
2168
- if ( _elements [ name ] != null )
2169
- {
2170
- return false ;
2171
- }
2172
2148
int i = _elements . Count ;
2173
- _elements . Add ( name , i ) ;
2174
- _particles [ i ] = particle ;
2175
- if ( ! isEmptiable )
2149
+ if ( _elements . TryAdd ( name , i ) )
2176
2150
{
2177
- _isRequired . Set ( i ) ;
2178
- _countRequired ++ ;
2151
+ _particles [ i ] = particle ;
2152
+ if ( ! isEmptiable )
2153
+ {
2154
+ _isRequired . Set ( i ) ;
2155
+ _countRequired ++ ;
2156
+ }
2157
+ return true ;
2179
2158
}
2180
- return true ;
2159
+
2160
+ return false ;
2181
2161
}
2182
2162
2183
2163
public override bool IsEmptiable
@@ -2194,15 +2174,14 @@ public override void InitValidation(ValidationState context)
2194
2174
2195
2175
public override object ? ValidateElement ( XmlQualifiedName name , ValidationState context , out int errorCode )
2196
2176
{
2197
- object ? lookup = _elements [ name ] ;
2198
2177
errorCode = 0 ;
2199
- if ( lookup == null )
2178
+
2179
+ if ( ! _elements . TryGetValue ( name , out int index ) )
2200
2180
{
2201
2181
context . NeedValidateChildren = false ;
2202
2182
return null ;
2203
2183
}
2204
2184
2205
- int index = ( int ) lookup ;
2206
2185
if ( context . AllElementsSet ! [ index ] )
2207
2186
{
2208
2187
errorCode = - 2 ;
@@ -2236,16 +2215,12 @@ public override bool CompleteValidation(ValidationState context)
2236
2215
public override ArrayList ? ExpectedElements ( ValidationState context , bool isRequiredOnly )
2237
2216
{
2238
2217
ArrayList ? names = null ;
2239
- foreach ( DictionaryEntry entry in _elements )
2218
+ foreach ( KeyValuePair < XmlQualifiedName , int > element in _elements )
2240
2219
{
2241
- if ( ! context . AllElementsSet ! [ ( int ) entry . Value ! ] && ( ! isRequiredOnly || _isRequired [ ( int ) entry . Value ] ) )
2220
+ if ( ! context . AllElementsSet ! [ element . Value ] && ( ! isRequiredOnly || _isRequired [ element . Value ] ) )
2242
2221
{
2243
- if ( names == null )
2244
- {
2245
- names = new ArrayList ( ) ;
2246
- }
2247
-
2248
- names . Add ( entry . Key ) ;
2222
+ names ??= new ArrayList ( ) ;
2223
+ names . Add ( element . Key ) ;
2249
2224
}
2250
2225
}
2251
2226
@@ -2255,11 +2230,11 @@ public override bool CompleteValidation(ValidationState context)
2255
2230
public override ArrayList ExpectedParticles ( ValidationState context , bool isRequiredOnly , XmlSchemaSet schemaSet )
2256
2231
{
2257
2232
ArrayList expectedParticles = new ArrayList ( ) ;
2258
- foreach ( DictionaryEntry entry in _elements )
2233
+ foreach ( KeyValuePair < XmlQualifiedName , int > element in _elements )
2259
2234
{
2260
- if ( ! context . AllElementsSet ! [ ( int ) entry . Value ! ] && ( ! isRequiredOnly || _isRequired [ ( int ) entry . Value ] ) )
2235
+ if ( ! context . AllElementsSet ! [ element . Value ] && ( ! isRequiredOnly || _isRequired [ element . Value ] ) )
2261
2236
{
2262
- AddParticleToExpected ( ( _particles [ ( int ) entry . Value ] as XmlSchemaParticle ) ! , schemaSet , expectedParticles ) ;
2237
+ AddParticleToExpected ( ( _particles [ element . Value ] as XmlSchemaParticle ) ! , schemaSet , expectedParticles ) ;
2263
2238
}
2264
2239
}
2265
2240
0 commit comments