Skip to content

Commit 17ea768

Browse files
committed
Fix compiler for new DNode logic
1 parent 0cef21e commit 17ea768

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

src/org/jruby/ast/DNode.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,11 @@ public boolean isSameEncoding(StrNode strNode) {
4545
}
4646

4747
protected RubyString allocateString(Ruby runtime) {
48-
if (!is19()) return runtime.newString();
48+
ByteList bytes = new ByteList();
4949

50-
// FIXME: Need a nicer constructor...
51-
return RubyString.newStringNoCopy(runtime, new ByteList(), encoding, StringSupport.CR_7BIT);
50+
if (is19()) bytes.setEncoding(encoding);
51+
52+
return RubyString.newStringShared(runtime, bytes, StringSupport.CR_7BIT);
5253
}
5354

5455
public void appendToString(Ruby runtime, ThreadContext context, IRubyObject self, Block aBlock, RubyString string, Node node) {

src/org/jruby/compiler/impl/BaseBodyCompiler.java

+7-10
Original file line numberDiff line numberDiff line change
@@ -450,19 +450,16 @@ public void createNewBignum(BigInteger value) {
450450

451451
public void createNewString(ArrayCallback callback, int count, Encoding encoding) {
452452
loadRuntime();
453-
454-
method.newobj(p(ByteList.class));
455-
method.dup();
456-
method.ldc(StandardASMCompiler.STARTING_DSTR_SIZE);
457-
method.invokespecial(p(ByteList.class), "<init>", sig(Void.TYPE, int.class));
453+
ByteList startingDstr = new ByteList(StandardASMCompiler.STARTING_DSTR_SIZE);
458454

459455
if (encoding != null) {
460-
script.getCacheCompiler().cacheEncoding(this, encoding);
461-
method.ldc(StringSupport.CR_7BIT);
462-
method.invokestatic(p(RubyString.class), "newStringNoCopy", sig(RubyString.class, Ruby.class, ByteList.class, Encoding.class, int.class));
463-
} else {
464-
method.invokestatic(p(RubyString.class), "newStringLight", sig(RubyString.class, Ruby.class, ByteList.class));
456+
startingDstr.setEncoding(encoding);
465457
}
458+
459+
script.getCacheCompiler().cacheByteList(this, startingDstr);
460+
method.invokevirtual(p(ByteList.class), "dup", sig(ByteList.class));
461+
method.ldc(StringSupport.CR_7BIT);
462+
method.invokestatic(p(RubyString.class), "newStringShared", sig(RubyString.class, Ruby.class, ByteList.class, int.class));
466463

467464
for (int i = 0; i < count; i++) {
468465
callback.nextValue(this, null, i);

0 commit comments

Comments
 (0)