|
73 | 73 | import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile;
|
74 | 74 | import com.oracle.graal.python.nodes.object.GetClassNode;
|
75 | 75 | import com.oracle.graal.python.nodes.util.CannotCastException;
|
76 |
| -import com.oracle.graal.python.nodes.util.CastToJavaIntExactNode; |
77 | 76 | import com.oracle.graal.python.nodes.util.CastToJavaStringNode;
|
78 | 77 | import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
|
79 | 78 | import com.oracle.graal.python.runtime.PythonOptions;
|
|
95 | 94 | import com.oracle.truffle.api.dsl.ImportStatic;
|
96 | 95 | import com.oracle.truffle.api.dsl.Specialization;
|
97 | 96 | import com.oracle.truffle.api.frame.VirtualFrame;
|
98 |
| -import com.oracle.truffle.api.interop.InteropLibrary; |
99 |
| -import com.oracle.truffle.api.library.CachedLibrary; |
100 | 97 | import com.oracle.truffle.api.nodes.Node;
|
101 | 98 | import com.oracle.truffle.api.profiles.InlinedConditionProfile;
|
102 | 99 | import com.oracle.truffle.api.strings.TruffleString;
|
@@ -160,27 +157,24 @@ static int doMaterialized(PString x,
|
160 | 157 | return doString(x.getMaterialized(), codePointLengthNode);
|
161 | 158 | }
|
162 | 159 |
|
163 |
| - @Specialization(guards = "x.isNativeCharSequence()") |
164 |
| - static int doNativeCharSequence(PString x, |
| 160 | + @Specialization(guards = {"x.isNativeCharSequence()", "isKnownLength(elements)"}) |
| 161 | + static int doNativeKnownLength(PString x, |
| 162 | + @Bind("x.getNativeCharSequence().getElements()") int elements) { |
| 163 | + return elements; |
| 164 | + } |
| 165 | + |
| 166 | + @Specialization(guards = {"x.isNativeCharSequence()", "!isKnownLength(elements)"}) |
| 167 | + static int doNativeUnknownLength(PString x, |
| 168 | + @SuppressWarnings("unused") @Bind("x.getNativeCharSequence().getElements()") int elements, |
165 | 169 | @Bind("this") Node inliningTarget,
|
166 | 170 | @Cached StringMaterializeNode materializeNode,
|
167 | 171 | @Shared @Cached TruffleString.CodePointLengthNode codePointLengthNode) {
|
168 | 172 | return doString(materializeNode.execute(inliningTarget, x), codePointLengthNode);
|
169 | 173 | }
|
170 | 174 |
|
171 |
| - @Specialization(guards = {"x.isNativeCharSequence()", "x.isNativeMaterialized()"}) |
172 |
| - static int nativeString(PString x, |
173 |
| - @Shared @Cached TruffleString.CodePointLengthNode codePointLengthNode) { |
174 |
| - return doString(x.getNativeCharSequence().getMaterialized(), codePointLengthNode); |
175 |
| - } |
176 |
| - |
177 |
| - @Specialization(guards = {"x.isNativeCharSequence()", "!x.isNativeMaterialized()"}, replaces = "nativeString", limit = "3") |
178 |
| - static int nativeStringMat(@SuppressWarnings("unused") PString x, |
179 |
| - @Bind("this") Node inliningTarget, |
180 |
| - @Bind("x.getNativeCharSequence()") NativeCharSequence ncs, |
181 |
| - @CachedLibrary("ncs") InteropLibrary lib, |
182 |
| - @Cached CastToJavaIntExactNode castToJavaIntNode) { |
183 |
| - return ncs.length(inliningTarget, lib, castToJavaIntNode); |
| 175 | + static boolean isKnownLength(int elements) { |
| 176 | + // -1 means we have to search for the null terminator to compute the length |
| 177 | + return elements != -1; |
184 | 178 | }
|
185 | 179 |
|
186 | 180 | @Specialization
|
|
0 commit comments