|
90 | 90 | import com.oracle.truffle.api.dsl.TypeSystemReference; |
91 | 91 | import com.oracle.truffle.api.frame.VirtualFrame; |
92 | 92 | import com.oracle.truffle.api.library.CachedLibrary; |
93 | | -import com.oracle.truffle.api.profiles.ValueProfile; |
94 | 93 |
|
95 | 94 | @CoreFunctions(defineModule = "_codecs") |
96 | 95 | public class CodecsModuleBuiltins extends PythonBuiltins { |
@@ -322,41 +321,41 @@ public abstract static class CodecsEncodeNode extends EncodeBaseNode { |
322 | 321 |
|
323 | 322 | @Specialization(guards = "isString(str)") |
324 | 323 | Object encode(Object str, @SuppressWarnings("unused") PNone encoding, @SuppressWarnings("unused") PNone errors, |
325 | | - @Cached("createClassProfile()") ValueProfile strTypeProfile) { |
326 | | - Object profiledStr = strTypeProfile.profile(str); |
327 | | - PBytes bytes = encodeString(profiledStr.toString(), "utf-8", "strict"); |
| 324 | + @Shared("castStr") @Cached CastToJavaStringNode castStr) { |
| 325 | + String profiledStr = castStr.execute(str); |
| 326 | + PBytes bytes = encodeString(profiledStr, "utf-8", "strict"); |
328 | 327 | return factory().createTuple(new Object[]{bytes, getLength(bytes)}); |
329 | 328 | } |
330 | 329 |
|
331 | 330 | @Specialization(guards = {"isString(str)", "isString(encoding)"}) |
332 | 331 | Object encode(Object str, Object encoding, @SuppressWarnings("unused") PNone errors, |
333 | | - @Cached("createClassProfile()") ValueProfile strTypeProfile, |
334 | | - @Cached("createClassProfile()") ValueProfile encodingTypeProfile) { |
335 | | - Object profiledStr = strTypeProfile.profile(str); |
336 | | - Object profiledEncoding = encodingTypeProfile.profile(encoding); |
337 | | - PBytes bytes = encodeString(profiledStr.toString(), profiledEncoding.toString(), "strict"); |
| 332 | + @Shared("castStr") @Cached CastToJavaStringNode castStr, |
| 333 | + @Shared("castEncoding") @Cached CastToJavaStringNode castEncoding) { |
| 334 | + String profiledStr = castStr.execute(str); |
| 335 | + String profiledEncoding = castEncoding.execute(encoding); |
| 336 | + PBytes bytes = encodeString(profiledStr, profiledEncoding, "strict"); |
338 | 337 | return factory().createTuple(new Object[]{bytes, getLength(bytes)}); |
339 | 338 | } |
340 | 339 |
|
341 | 340 | @Specialization(guards = {"isString(str)", "isString(errors)"}) |
342 | 341 | Object encode(Object str, @SuppressWarnings("unused") PNone encoding, Object errors, |
343 | | - @Cached("createClassProfile()") ValueProfile strTypeProfile, |
344 | | - @Cached("createClassProfile()") ValueProfile errorsTypeProfile) { |
345 | | - Object profiledStr = strTypeProfile.profile(str); |
346 | | - Object profiledErrors = errorsTypeProfile.profile(errors); |
347 | | - PBytes bytes = encodeString(profiledStr.toString(), "utf-8", profiledErrors.toString()); |
| 342 | + @Shared("castStr") @Cached CastToJavaStringNode castStr, |
| 343 | + @Shared("castErrors") @Cached CastToJavaStringNode castErrors) { |
| 344 | + String profiledStr = castStr.execute(str); |
| 345 | + String profiledErrors = castErrors.execute(errors); |
| 346 | + PBytes bytes = encodeString(profiledStr, "utf-8", profiledErrors); |
348 | 347 | return factory().createTuple(new Object[]{bytes, getLength(bytes)}); |
349 | 348 | } |
350 | 349 |
|
351 | 350 | @Specialization(guards = {"isString(str)", "isString(encoding)", "isString(errors)"}) |
352 | 351 | Object encode(Object str, Object encoding, Object errors, |
353 | | - @Cached("createClassProfile()") ValueProfile strTypeProfile, |
354 | | - @Cached("createClassProfile()") ValueProfile encodingTypeProfile, |
355 | | - @Cached("createClassProfile()") ValueProfile errorsTypeProfile) { |
356 | | - Object profiledStr = strTypeProfile.profile(str); |
357 | | - Object profiledEncoding = encodingTypeProfile.profile(encoding); |
358 | | - Object profiledErrors = errorsTypeProfile.profile(errors); |
359 | | - PBytes bytes = encodeString(profiledStr.toString(), profiledEncoding.toString(), profiledErrors.toString()); |
| 352 | + @Shared("castStr") @Cached CastToJavaStringNode castStr, |
| 353 | + @Shared("castEncoding") @Cached CastToJavaStringNode castEncoding, |
| 354 | + @Shared("castErrors") @Cached CastToJavaStringNode castErrors) { |
| 355 | + String profiledStr = castStr.execute(str); |
| 356 | + String profiledEncoding = castEncoding.execute(encoding); |
| 357 | + String profiledErrors = castErrors.execute(errors); |
| 358 | + PBytes bytes = encodeString(profiledStr, profiledEncoding, profiledErrors); |
360 | 359 | return factory().createTuple(new Object[]{bytes, getLength(bytes)}); |
361 | 360 | } |
362 | 361 |
|
@@ -546,9 +545,9 @@ Object decode(PIBytesLike bytes, @SuppressWarnings("unused") PNone errors) { |
546 | 545 |
|
547 | 546 | @Specialization(guards = {"isString(errors)"}) |
548 | 547 | Object decode(PIBytesLike bytes, Object errors, |
549 | | - @Cached("createClassProfile()") ValueProfile errorsTypeProfile) { |
550 | | - Object profiledErrors = errorsTypeProfile.profile(errors); |
551 | | - String string = decodeBytes(getBytesBuffer(bytes), profiledErrors.toString()); |
| 548 | + @Cached CastToJavaStringNode castStr) { |
| 549 | + String profiledErrors = castStr.execute(errors); |
| 550 | + String string = decodeBytes(getBytesBuffer(bytes), profiledErrors); |
552 | 551 | return factory().createTuple(new Object[]{string, string.length()}); |
553 | 552 | } |
554 | 553 |
|
|
0 commit comments