@@ -272,9 +272,9 @@ public static WriteableScope create(Symbol owner) {
272
272
}
273
273
274
274
private static class ScopeImpl extends WriteableScope {
275
- /** The number of scopes that share this scope's hash table.
275
+ /** true if this scope's hash table is shared with a nested scope .
276
276
*/
277
- private int shared ;
277
+ private boolean shared ;
278
278
279
279
/** Next enclosing scope (with whom this scope may share a hashtable)
280
280
*/
@@ -339,8 +339,10 @@ public ScopeImpl(Symbol owner) {
339
339
* of fresh tables.
340
340
*/
341
341
public WriteableScope dup (Symbol newOwner ) {
342
+ Assert .check (!shared );
343
+
342
344
ScopeImpl result = new ScopeImpl (this , newOwner , this .table , this .nelems );
343
- shared ++ ;
345
+ shared = true ;
344
346
// System.out.println("====> duping scope " + this.hashCode() + " owned by " + newOwner + " to " + result.hashCode());
345
347
// new Error().printStackTrace(System.out);
346
348
return result ;
@@ -351,7 +353,7 @@ public WriteableScope dup(Symbol newOwner) {
351
353
* the table of its outer scope.
352
354
*/
353
355
public WriteableScope dupUnshared (Symbol newOwner ) {
354
- if (shared > 0 ) {
356
+ if (shared ) {
355
357
//The nested Scopes might have already added something to the table, so all items
356
358
//that don't originate in this Scope or any of its outer Scopes need to be cleared:
357
359
Set <Scope > acceptScopes = Collections .newSetFromMap (new IdentityHashMap <>());
@@ -383,7 +385,7 @@ public WriteableScope dupUnshared(Symbol newOwner) {
383
385
* with next.
384
386
*/
385
387
public WriteableScope leave () {
386
- Assert .check (shared == 0 );
388
+ Assert .check (! shared );
387
389
if (table != next .table ) return next ;
388
390
while (elems != null ) {
389
391
int hash = getIndex (elems .sym .name );
@@ -392,8 +394,8 @@ public WriteableScope leave() {
392
394
table [hash ] = elems .shadowed ;
393
395
elems = elems .nextSibling ;
394
396
}
395
- Assert .check (next .shared > 0 );
396
- next .shared -- ;
397
+ Assert .check (next .shared );
398
+ next .shared = false ;
397
399
next .nelems = nelems ;
398
400
// System.out.println("====> leaving scope " + this.hashCode() + " owned by " + this.owner + " to " + next.hashCode());
399
401
// new Error().printStackTrace(System.out);
@@ -403,12 +405,12 @@ public WriteableScope leave() {
403
405
/** Double size of hash table.
404
406
*/
405
407
private void dble () {
406
- Assert .check (shared == 0 );
408
+ Assert .check (! shared );
407
409
Entry [] oldtable = table ;
408
410
Entry [] newtable = new Entry [oldtable .length * 2 ];
409
411
for (ScopeImpl s = this ; s != null ; s = s .next ) {
410
412
if (s .table == oldtable ) {
411
- Assert .check (s == this || s .shared != 0 );
413
+ Assert .check (s == this || s .shared );
412
414
s .table = newtable ;
413
415
s .hashMask = newtable .length - 1 ;
414
416
}
@@ -429,7 +431,7 @@ private void dble() {
429
431
/** Enter symbol sym in this scope.
430
432
*/
431
433
public void enter (Symbol sym ) {
432
- Assert .check (shared == 0 );
434
+ Assert .check (! shared );
433
435
if (nelems * 3 >= hashMask * 2 )
434
436
dble ();
435
437
int hash = getIndex (sym .name );
@@ -449,7 +451,7 @@ public void enter(Symbol sym) {
449
451
/** Remove symbol from this scope.
450
452
*/
451
453
public void remove (Symbol sym ) {
452
- Assert .check (shared == 0 );
454
+ Assert .check (! shared );
453
455
Entry e = lookup (sym .name , candidate -> candidate == sym );
454
456
if (e .scope == null ) return ;
455
457
@@ -487,7 +489,7 @@ else while (true) {
487
489
/** Enter symbol sym in this scope if not already there.
488
490
*/
489
491
public void enterIfAbsent (Symbol sym ) {
490
- Assert .check (shared == 0 );
492
+ Assert .check (! shared );
491
493
Entry e = lookup (sym .name );
492
494
while (e .scope == this && e .sym .kind != sym .kind ) e = e .next ();
493
495
if (e .scope != this ) enter (sym );
0 commit comments