|
10 | 10 | package org.truffleruby.parser.parser;
|
11 | 11 |
|
12 | 12 | import com.oracle.truffle.api.CompilerDirectives;
|
13 |
| -import com.oracle.truffle.api.TruffleOptions; |
14 | 13 | import org.jcodings.Encoding;
|
15 |
| -import org.truffleruby.RubyContext; |
16 | 14 | import org.truffleruby.core.rope.Rope;
|
17 | 15 | import org.truffleruby.core.rope.RopeNodes;
|
18 |
| -import org.truffleruby.core.rope.RopeOperations; |
19 | 16 | import org.truffleruby.language.RubyBaseNode;
|
20 |
| -import java.util.Arrays; |
21 |
| -import static org.truffleruby.core.rope.CodeRange.CR_7BIT; |
22 |
| -import static org.truffleruby.core.rope.CodeRange.CR_UNKNOWN; |
23 | 17 |
|
24 | 18 | public class ParserRopeOperations {
|
25 | 19 |
|
26 | 20 | public Rope withEncoding(Rope rope, Encoding encoding) {
|
27 |
| - if (isBuildingNativeImage()) { |
28 |
| - if (rope.isAsciiOnly() && encoding.isAsciiCompatible()) { |
29 |
| - return rope.withEncoding(encoding, CR_7BIT); |
30 |
| - } |
31 |
| - |
32 |
| - return RopeOperations.create(rope.getBytes(), encoding, CR_UNKNOWN); |
33 |
| - } else { |
34 |
| - return ropeNode.getWithEncodingNode().executeWithEncoding(rope, encoding); |
35 |
| - } |
| 21 | + return ropeNode.getWithEncodingNode().executeWithEncoding(rope, encoding); |
36 | 22 | }
|
37 | 23 |
|
38 | 24 | public Rope makeShared(Rope rope, int sharedStart, int sharedLength) {
|
39 |
| - if (isBuildingNativeImage()) { |
40 |
| - if (sharedLength == rope.byteLength()) { |
41 |
| - return rope; |
42 |
| - } |
43 |
| - |
44 |
| - return RopeOperations.create(Arrays.copyOfRange(rope.getBytes(), sharedStart, sharedStart + sharedLength), rope.getEncoding(), rope.isAsciiOnly() ? CR_7BIT : CR_UNKNOWN); |
45 |
| - } else { |
46 |
| - return ropeNode.getSubstringNode().executeSubstring(rope, sharedStart, sharedLength); |
47 |
| - } |
48 |
| - } |
49 |
| - |
50 |
| - private static boolean isBuildingNativeImage() { |
51 |
| - // We can't use a detached RopeNode during image construction because it trips up the static analysis, but |
52 |
| - // we can use it at runtime. We check if a context has been created as a proxy for whether we're in the native |
53 |
| - // image builder or running at runtime. |
54 |
| - return TruffleOptions.AOT && RubyContext.FIRST_INSTANCE == null; |
| 25 | + return ropeNode.getSubstringNode().executeSubstring(rope, sharedStart, sharedLength); |
55 | 26 | }
|
56 | 27 |
|
57 | 28 | private static class RopeNode extends RubyBaseNode {
|
@@ -79,6 +50,6 @@ public RopeNodes.WithEncodingNode getWithEncodingNode() {
|
79 | 50 |
|
80 | 51 | }
|
81 | 52 |
|
82 |
| - private final RopeNode ropeNode = isBuildingNativeImage() ? null : new RopeNode(); |
| 53 | + private final RopeNode ropeNode = new RopeNode(); |
83 | 54 |
|
84 | 55 | }
|
0 commit comments