45
45
import com .oracle .graal .python .builtins .objects .common .HashingCollectionNodesFactory .GetDictStorageNodeGen ;
46
46
import com .oracle .graal .python .nodes .PGuards ;
47
47
import com .oracle .graal .python .nodes .PNodeWithContext ;
48
+ import com .oracle .truffle .api .CompilerDirectives ;
48
49
import com .oracle .truffle .api .dsl .Cached ;
49
50
import com .oracle .truffle .api .dsl .ImportStatic ;
50
51
import com .oracle .truffle .api .dsl .Specialization ;
@@ -53,14 +54,27 @@ public abstract class HashingCollectionNodes {
53
54
54
55
@ ImportStatic (PGuards .class )
55
56
public abstract static class LenNode extends PNodeWithContext {
57
+ private @ Child HashingStorageNodes .LenNode lenNode ;
58
+
59
+ public HashingStorageNodes .LenNode getLenNode () {
60
+ if (lenNode == null ) {
61
+ CompilerDirectives .transferToInterpreterAndInvalidate ();
62
+ lenNode = insert (HashingStorageNodes .LenNode .create ());
63
+ }
64
+ return lenNode ;
65
+ }
56
66
57
67
public abstract int execute (PHashingCollection c );
58
68
59
69
@ Specialization (limit = "4" , guards = {"c.getClass() == cachedClass" })
60
- int doWithStorage (PHashingCollection c ,
61
- @ Cached ("c.getClass()" ) Class <? extends PHashingCollection > cachedClass ,
62
- @ Cached ("create()" ) HashingStorageNodes .LenNode lenNode ) {
63
- return lenNode .execute (cachedClass .cast (c ).getDictStorage ());
70
+ int getLenCached (PHashingCollection c ,
71
+ @ Cached ("c.getClass()" ) Class <? extends PHashingCollection > cachedClass ) {
72
+ return getLenNode ().execute (cachedClass .cast (c ).getDictStorage ());
73
+ }
74
+
75
+ @ Specialization (replaces = "getLenCached" )
76
+ int getLenGeneric (PHashingCollection c ) {
77
+ return getLenNode ().execute (c .getDictStorage ());
64
78
}
65
79
66
80
public static LenNode create () {
@@ -70,14 +84,27 @@ public static LenNode create() {
70
84
71
85
@ ImportStatic (PGuards .class )
72
86
public abstract static class SetItemNode extends PNodeWithContext {
87
+ private @ Child HashingStorageNodes .SetItemNode setItemNode ;
88
+
89
+ public HashingStorageNodes .SetItemNode getSetItemNode () {
90
+ if (setItemNode == null ) {
91
+ CompilerDirectives .transferToInterpreterAndInvalidate ();
92
+ setItemNode = insert (HashingStorageNodes .SetItemNode .create ());
93
+ }
94
+ return setItemNode ;
95
+ }
73
96
74
97
public abstract void execute (PHashingCollection c , Object key , Object value );
75
98
76
99
@ Specialization (limit = "4" , guards = {"c.getClass() == cachedClass" })
77
- void doWithStorage (PHashingCollection c , Object key , Object value ,
78
- @ Cached ("c.getClass()" ) Class <? extends PHashingCollection > cachedClass ,
79
- @ Cached ("create()" ) HashingStorageNodes .SetItemNode setNode ) {
80
- cachedClass .cast (c ).setDictStorage (setNode .execute (cachedClass .cast (c ).getDictStorage (), key , value ));
100
+ void doSetItemCached (PHashingCollection c , Object key , Object value ,
101
+ @ Cached ("c.getClass()" ) Class <? extends PHashingCollection > cachedClass ) {
102
+ cachedClass .cast (c ).setDictStorage (getSetItemNode ().execute (cachedClass .cast (c ).getDictStorage (), key , value ));
103
+ }
104
+
105
+ @ Specialization (replaces = "doSetItemCached" )
106
+ void doSetItemGeneric (PHashingCollection c , Object key , Object value ) {
107
+ c .setDictStorage (getSetItemNode ().execute (c .getDictStorage (), key , value ));
81
108
}
82
109
83
110
public static SetItemNode create () {
@@ -91,11 +118,16 @@ public abstract static class GetDictStorageNode extends PNodeWithContext {
91
118
public abstract HashingStorage execute (PHashingCollection c );
92
119
93
120
@ Specialization (limit = "4" , guards = {"c.getClass() == cachedClass" })
94
- HashingStorage doWithStorage (PHashingCollection c ,
121
+ HashingStorage getStorageCached (PHashingCollection c ,
95
122
@ Cached ("c.getClass()" ) Class <? extends PHashingCollection > cachedClass ) {
96
123
return cachedClass .cast (c ).getDictStorage ();
97
124
}
98
125
126
+ @ Specialization (replaces = "getStorageCached" )
127
+ HashingStorage getStorageGeneric (PHashingCollection c ) {
128
+ return c .getDictStorage ();
129
+ }
130
+
99
131
public static GetDictStorageNode create () {
100
132
return GetDictStorageNodeGen .create ();
101
133
}
0 commit comments