Skip to content

Commit 0b73efc

Browse files
committed
Avoid copying native ropes when setting encoding.
1 parent 5860ff4 commit 0b73efc

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/main/java/org/truffleruby/core/rope/NativeRope.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public String toString() {
178178

179179
@Override
180180
public Rope withEncoding(Encoding newEncoding, CodeRange newCodeRange) {
181-
return RopeOperations.create(getBytes(), newEncoding, newCodeRange);
181+
return new NativeRope(pointer, byteLength(), newEncoding, UNKNOWN_CHARACTER_LENGTH, CodeRange.CR_UNKNOWN);
182182
}
183183

184184
public Pointer getNativePointer() {

src/main/java/org/truffleruby/core/rope/RopeNodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -976,7 +976,7 @@ protected Rope withEncodingSameEncoding(Rope rope, Encoding encoding) {
976976

977977
@Specialization(guards = "rope.getEncoding() != encoding")
978978
protected Rope nativeRopeWithEncoding(NativeRope rope, Encoding encoding) {
979-
return rescanBytesForEncoding(rope, encoding);
979+
return rope.withEncoding(encoding, rope.getCodeRange());
980980
}
981981

982982
@Specialization(guards = {

0 commit comments

Comments
 (0)