60
60
import static com .oracle .graal .python .nodes .StringLiterals .T_NONE ;
61
61
import static com .oracle .graal .python .runtime .exception .PythonErrorType .AttributeError ;
62
62
import static com .oracle .graal .python .runtime .exception .PythonErrorType .TypeError ;
63
+ import static com .oracle .graal .python .util .PythonUtils .TS_ENCODING ;
63
64
64
65
import java .util .List ;
65
66
130
131
import com .oracle .graal .python .nodes .util .CannotCastException ;
131
132
import com .oracle .graal .python .nodes .util .CastToTruffleStringNode ;
132
133
import com .oracle .graal .python .nodes .util .SplitArgsNode ;
134
+ import com .oracle .truffle .api .CompilerAsserts ;
133
135
import com .oracle .truffle .api .CompilerDirectives ;
134
136
import com .oracle .truffle .api .CompilerDirectives .CompilationFinal ;
135
137
import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
139
141
import com .oracle .truffle .api .dsl .ImportStatic ;
140
142
import com .oracle .truffle .api .dsl .NodeFactory ;
141
143
import com .oracle .truffle .api .dsl .Specialization ;
144
+ import com .oracle .truffle .api .dsl .Cached .Shared ;
142
145
import com .oracle .truffle .api .frame .VirtualFrame ;
143
146
import com .oracle .truffle .api .interop .InteropLibrary ;
144
147
import com .oracle .truffle .api .library .CachedLibrary ;
@@ -395,10 +398,26 @@ public abstract static class GetAttributeNode extends PythonBinaryBuiltinNode {
395
398
@ Child private ReadAttributeFromObjectNode attrRead ;
396
399
@ Child private GetClassNode getDescClassNode ;
397
400
401
+ protected static int tsLen (TruffleString ts ) {
402
+ CompilerAsserts .neverPartOfCompilation ();
403
+ return TruffleString .CodePointLengthNode .getUncached ().execute (ts , TS_ENCODING );
404
+ }
405
+
406
+ // Shortcut, only useful for interpreter performance, but doesn't hurt peak
407
+ @ Specialization (guards = {"keyObj == cachedKey" , "tsLen(cachedKey) < 32" }, limit = "1" )
408
+ protected Object doItTruffleString (VirtualFrame frame , Object object , @ SuppressWarnings ("unused" ) TruffleString keyObj ,
409
+ @ SuppressWarnings ("unused" ) @ Cached ("keyObj" ) TruffleString cachedKey ,
410
+ @ Shared ("getClassNode" ) @ Cached GetClassNode getClassNode ,
411
+ @ Cached ("create(cachedKey)" ) LookupAttributeInMRONode lookup ) {
412
+ Object type = getClassNode .execute (object );
413
+ Object descr = lookup .execute (type );
414
+ return fullLookup (frame , object , cachedKey , type , descr );
415
+ }
416
+
398
417
@ Specialization
399
418
protected Object doIt (VirtualFrame frame , Object object , Object keyObj ,
400
419
@ Cached LookupAttributeInMRONode .Dynamic lookup ,
401
- @ Cached GetClassNode getClassNode ,
420
+ @ Shared ( "getClassNode" ) @ Cached GetClassNode getClassNode ,
402
421
@ Cached CastToTruffleStringNode castKeyToStringNode ) {
403
422
TruffleString key ;
404
423
try {
@@ -409,6 +428,10 @@ protected Object doIt(VirtualFrame frame, Object object, Object keyObj,
409
428
410
429
Object type = getClassNode .execute (object );
411
430
Object descr = lookup .execute (type , key );
431
+ return fullLookup (frame , object , key , type , descr );
432
+ }
433
+
434
+ private Object fullLookup (VirtualFrame frame , Object object , TruffleString key , Object type , Object descr ) {
412
435
Object dataDescClass = null ;
413
436
boolean hasDescr = descr != PNone .NO_VALUE ;
414
437
if (hasDescr && (profileFlags & HAS_DESCR ) == 0 ) {
0 commit comments