@@ -81,7 +81,6 @@ public boolean equals(Object a, Object b) {
81
81
return (a == b ) || (a != null && objectEquals (a , b ));
82
82
}
83
83
84
- @ TruffleBoundary
85
84
private boolean objectEquals (Object a , Object b ) {
86
85
return a .equals (b );
87
86
}
@@ -134,24 +133,23 @@ public int hashCode() {
134
133
}
135
134
}
136
135
137
- private final PEMap < DictKey , Object > map ;
136
+ private final PEMap map ;
138
137
139
- private EconomicMapStorage () {
140
- this .map = new PEMap <>( );
138
+ private EconomicMapStorage (int initialCapacity ) {
139
+ this .map = PEMap . create ( EconomicMapStorage . DEFAULT_EQIVALENCE , initialCapacity , false );
141
140
}
142
141
143
- private EconomicMapStorage (int initialCapacity ) {
144
- this . map = new PEMap <>( initialCapacity );
142
+ private EconomicMapStorage () {
143
+ this ( 4 );
145
144
}
146
145
147
146
private EconomicMapStorage (EconomicMapStorage original ) {
148
- this . map = new PEMap <> (original .map .size ());
147
+ this (original .map .size ());
149
148
this .map .putAll (original .map );
150
149
}
151
150
152
- @ TruffleBoundary
153
151
public EconomicMapStorage (EconomicMap <? extends Object , ? extends Object > map ) {
154
- this . map = new PEMap <> (map .size ());
152
+ this (map .size ());
155
153
MapCursor <? extends Object , ? extends Object > c = map .getEntries ();
156
154
while (c .advance ()) {
157
155
Object key = c .getKey ();
@@ -255,7 +253,6 @@ public HashingStorage delItemWithState(Object key, ThreadState state,
255
253
256
254
@ Override
257
255
@ ExportMessage
258
- @ TruffleBoundary
259
256
public HashingStorage [] injectInto (HashingStorage [] firstValue , InjectIntoNode node ) {
260
257
HashingStorage [] result = firstValue ;
261
258
MapCursor <DictKey , Object > cursor = map .getEntries ();
@@ -274,7 +271,6 @@ static HashingStorage toSameType(EconomicMapStorage self, EconomicMapStorage oth
274
271
}
275
272
276
273
@ Specialization
277
- @ TruffleBoundary
278
274
static HashingStorage generic (EconomicMapStorage self , HashingStorage other ,
279
275
@ CachedLibrary (limit = "1" ) HashingStorageLibrary lib ) {
280
276
HashingStorage result = other ;
@@ -302,34 +298,34 @@ public HashingStorage copy() {
302
298
@ ExportMessage
303
299
public static class EqualsWithState {
304
300
@ Specialization
305
- @ TruffleBoundary
306
- static boolean toSameType ( EconomicMapStorage self , EconomicMapStorage other , ThreadState state ,
307
- @ CachedLibrary (limit = "3 " ) PythonObjectLibrary compareLib ) {
301
+ static boolean equalSameType ( EconomicMapStorage self , EconomicMapStorage other , ThreadState state ,
302
+ @ CachedLibrary ( limit = "5" ) PythonObjectLibrary compareLib1 ,
303
+ @ CachedLibrary (limit = "5 " ) PythonObjectLibrary compareLib2 ) {
308
304
if (self .map .size () != other .map .size ()) {
309
305
return false ;
310
306
}
311
307
MapCursor <DictKey , Object > cursor = self .map .getEntries ();
312
308
while (cursor .advance ()) {
313
309
Object otherValue = other .map .get (cursor .getKey ());
314
- if (otherValue != null && !compareLib .equalsWithState (otherValue , cursor .getValue (), compareLib , state )) {
310
+ if (otherValue != null && !compareLib1 .equalsWithState (otherValue , cursor .getValue (), compareLib2 , state )) {
315
311
return false ;
316
312
}
317
313
}
318
314
return true ;
319
315
}
320
316
321
317
@ Specialization
322
- @ TruffleBoundary
323
- static boolean generic ( EconomicMapStorage self , HashingStorage other , ThreadState state ,
324
- @ CachedLibrary (limit = "1 " ) HashingStorageLibrary lib ,
325
- @ CachedLibrary (limit = "3 " ) PythonObjectLibrary compareLib ) {
318
+ static boolean equalGeneric ( EconomicMapStorage self , HashingStorage other , ThreadState state ,
319
+ @ CachedLibrary ( limit = "5" ) HashingStorageLibrary lib ,
320
+ @ CachedLibrary (limit = "5 " ) PythonObjectLibrary compareLib1 ,
321
+ @ CachedLibrary (limit = "5 " ) PythonObjectLibrary compareLib2 ) {
326
322
if (self .map .size () != lib .lengthWithState (other , state )) {
327
323
return false ;
328
324
}
329
325
MapCursor <DictKey , Object > cursor = self .map .getEntries ();
330
326
while (cursor .advance ()) {
331
327
Object otherValue = lib .getItemWithState (self , cursor .getKey ().value , state );
332
- if (otherValue != null && !compareLib .equalsWithState (otherValue , cursor .getValue (), compareLib , state )) {
328
+ if (otherValue != null && !compareLib1 .equalsWithState (otherValue , cursor .getValue (), compareLib2 , state )) {
333
329
return false ;
334
330
}
335
331
}
@@ -339,9 +335,8 @@ static boolean generic(EconomicMapStorage self, HashingStorage other, ThreadStat
339
335
340
336
@ ExportMessage
341
337
public static class CompareKeys {
342
- @ TruffleBoundary
343
338
@ Specialization
344
- static int toSameType (EconomicMapStorage self , EconomicMapStorage other ) {
339
+ static int compareSameType (EconomicMapStorage self , EconomicMapStorage other ) {
345
340
int size = self .map .size ();
346
341
int size2 = other .map .size ();
347
342
if (size > size2 ) {
@@ -360,9 +355,8 @@ static int toSameType(EconomicMapStorage self, EconomicMapStorage other) {
360
355
}
361
356
}
362
357
363
- @ TruffleBoundary
364
- @ Specialization (limit = "1" )
365
- static int generic (EconomicMapStorage self , HashingStorage other ,
358
+ @ Specialization (limit = "4" )
359
+ static int compareGeneric (EconomicMapStorage self , HashingStorage other ,
366
360
@ CachedLibrary ("other" ) HashingStorageLibrary lib ) {
367
361
int size = self .map .size ();
368
362
int length = lib .length (other );
@@ -386,8 +380,7 @@ static int generic(EconomicMapStorage self, HashingStorage other,
386
380
@ ExportMessage
387
381
public static class Intersect {
388
382
@ Specialization
389
- @ TruffleBoundary
390
- static HashingStorage toSameType (EconomicMapStorage self , EconomicMapStorage other ) {
383
+ static HashingStorage intersectSameType (EconomicMapStorage self , EconomicMapStorage other ) {
391
384
EconomicMapStorage result = EconomicMapStorage .create ();
392
385
MapCursor <DictKey , Object > cursor = self .map .getEntries ();
393
386
while (cursor .advance ()) {
@@ -398,10 +391,9 @@ static HashingStorage toSameType(EconomicMapStorage self, EconomicMapStorage oth
398
391
return result ;
399
392
}
400
393
401
- @ Specialization
402
- @ TruffleBoundary
403
- static HashingStorage generic (EconomicMapStorage self , HashingStorage other ,
404
- @ CachedLibrary (limit = "1" ) HashingStorageLibrary lib ) {
394
+ @ Specialization (limit = "4" )
395
+ static HashingStorage intersectGeneric (EconomicMapStorage self , HashingStorage other ,
396
+ @ CachedLibrary ("other" ) HashingStorageLibrary lib ) {
405
397
EconomicMapStorage result = EconomicMapStorage .create ();
406
398
MapCursor <DictKey , Object > cursor = self .map .getEntries ();
407
399
while (cursor .advance ()) {
@@ -416,8 +408,7 @@ static HashingStorage generic(EconomicMapStorage self, HashingStorage other,
416
408
@ ExportMessage
417
409
public static class Diff {
418
410
@ Specialization
419
- @ TruffleBoundary
420
- static HashingStorage toSameType (EconomicMapStorage self , EconomicMapStorage other ) {
411
+ static HashingStorage diffSameType (EconomicMapStorage self , EconomicMapStorage other ) {
421
412
EconomicMapStorage result = EconomicMapStorage .create ();
422
413
MapCursor <DictKey , Object > cursor = self .map .getEntries ();
423
414
while (cursor .advance ()) {
@@ -428,10 +419,9 @@ static HashingStorage toSameType(EconomicMapStorage self, EconomicMapStorage oth
428
419
return result ;
429
420
}
430
421
431
- @ Specialization
432
- @ TruffleBoundary
433
- static HashingStorage generic (EconomicMapStorage self , HashingStorage other ,
434
- @ CachedLibrary (limit = "1" ) HashingStorageLibrary lib ) {
422
+ @ Specialization (limit = "4" )
423
+ static HashingStorage diffGeneric (EconomicMapStorage self , HashingStorage other ,
424
+ @ CachedLibrary ("other" ) HashingStorageLibrary lib ) {
435
425
EconomicMapStorage result = EconomicMapStorage .create ();
436
426
MapCursor <DictKey , Object > cursor = self .map .getEntries ();
437
427
while (cursor .advance ()) {
@@ -481,128 +471,3 @@ public String toString() {
481
471
return builder .toString ();
482
472
}
483
473
}
484
-
485
- final class PEMap <K , V > {
486
- private final EconomicMap <K , V > map ;
487
-
488
- @ TruffleBoundary
489
- PEMap (int initialCapacity ) {
490
- this .map = EconomicMap .create (EconomicMapStorage .DEFAULT_EQIVALENCE , initialCapacity );
491
- }
492
-
493
- PEMap () {
494
- this (4 );
495
- }
496
-
497
- @ TruffleBoundary
498
- public V get (K key ) {
499
- return map .get (key );
500
- }
501
-
502
- @ TruffleBoundary
503
- public boolean containsKey (K key ) {
504
- return map .containsKey (key );
505
- }
506
-
507
- @ TruffleBoundary
508
- public int size () {
509
- return map .size ();
510
- }
511
-
512
- @ TruffleBoundary
513
- public boolean isEmpty () {
514
- return map .isEmpty ();
515
- }
516
-
517
- @ TruffleBoundary
518
- public Iterable <K > getKeys () {
519
- return new KeysIterable <>(map .getKeys ());
520
- }
521
-
522
- private static final class KeysIterable <K > implements Iterable <K > {
523
- private final Iterable <K > keysIterable ;
524
-
525
- private KeysIterable (Iterable <K > keysIterable ) {
526
- this .keysIterable = keysIterable ;
527
- }
528
-
529
- @ TruffleBoundary
530
- public Iterator <K > iterator () {
531
- return new KeysIterator <>(keysIterable .iterator ());
532
- }
533
- }
534
-
535
- private static final class KeysIterator <K > implements Iterator <K > {
536
- private final Iterator <K > keysIterator ;
537
-
538
- KeysIterator (Iterator <K > iter ) {
539
- this .keysIterator = iter ;
540
- }
541
-
542
- @ TruffleBoundary
543
- public boolean hasNext () {
544
- return keysIterator .hasNext ();
545
- }
546
-
547
- @ TruffleBoundary
548
- public K next () {
549
- return keysIterator .next ();
550
- }
551
- }
552
-
553
- @ TruffleBoundary
554
- public V put (K key , V value ) {
555
- return map .put (key , value );
556
- }
557
-
558
- @ TruffleBoundary
559
- public void clear () {
560
- map .clear ();
561
- }
562
-
563
- @ TruffleBoundary
564
- public V removeKey (K key ) {
565
- return map .removeKey (key );
566
- }
567
-
568
- @ TruffleBoundary
569
- public MapCursor <K , V > getEntries () {
570
- return new EntriesMapCursor <>(map .getEntries ());
571
- }
572
-
573
- @ TruffleBoundary
574
- public void putAll (PEMap <K , V > other ) {
575
- MapCursor <K , V > e = other .getEntries ();
576
- while (e .advance ()) {
577
- put (e .getKey (), e .getValue ());
578
- }
579
- }
580
-
581
- private static final class EntriesMapCursor <K , V > implements MapCursor <K , V > {
582
- private final MapCursor <K , V > mapCursor ;
583
-
584
- public EntriesMapCursor (MapCursor <K , V > mapCursor ) {
585
- this .mapCursor = mapCursor ;
586
- }
587
-
588
- @ TruffleBoundary
589
- public boolean advance () {
590
- return mapCursor .advance ();
591
- }
592
-
593
- @ TruffleBoundary
594
- public K getKey () {
595
- return mapCursor .getKey ();
596
- }
597
-
598
- @ TruffleBoundary
599
- public V getValue () {
600
- return mapCursor .getValue ();
601
- }
602
-
603
- @ TruffleBoundary
604
- public void remove () {
605
- mapCursor .remove ();
606
- }
607
- }
608
- }
0 commit comments