Permalink
Browse files

Fix compiler for new DNode logic

  • Loading branch information...
1 parent 0cef21e commit 17ea7681901ea6b0d069a3d1ebf1bcd9331ca43b @enebo enebo committed Aug 23, 2011
Showing with 11 additions and 13 deletions.
  1. +4 −3 src/org/jruby/ast/DNode.java
  2. +7 −10 src/org/jruby/compiler/impl/BaseBodyCompiler.java
@@ -45,10 +45,11 @@ public boolean isSameEncoding(StrNode strNode) {
}
protected RubyString allocateString(Ruby runtime) {
- if (!is19()) return runtime.newString();
+ ByteList bytes = new ByteList();
- // FIXME: Need a nicer constructor...
- return RubyString.newStringNoCopy(runtime, new ByteList(), encoding, StringSupport.CR_7BIT);
+ if (is19()) bytes.setEncoding(encoding);
+
+ return RubyString.newStringShared(runtime, bytes, StringSupport.CR_7BIT);
}
public void appendToString(Ruby runtime, ThreadContext context, IRubyObject self, Block aBlock, RubyString string, Node node) {
@@ -450,19 +450,16 @@ public void createNewBignum(BigInteger value) {
public void createNewString(ArrayCallback callback, int count, Encoding encoding) {
loadRuntime();
-
- method.newobj(p(ByteList.class));
- method.dup();
- method.ldc(StandardASMCompiler.STARTING_DSTR_SIZE);
- method.invokespecial(p(ByteList.class), "<init>", sig(Void.TYPE, int.class));
+ ByteList startingDstr = new ByteList(StandardASMCompiler.STARTING_DSTR_SIZE);
if (encoding != null) {
- script.getCacheCompiler().cacheEncoding(this, encoding);
- method.ldc(StringSupport.CR_7BIT);
- method.invokestatic(p(RubyString.class), "newStringNoCopy", sig(RubyString.class, Ruby.class, ByteList.class, Encoding.class, int.class));
- } else {
- method.invokestatic(p(RubyString.class), "newStringLight", sig(RubyString.class, Ruby.class, ByteList.class));
+ startingDstr.setEncoding(encoding);
}
+
+ script.getCacheCompiler().cacheByteList(this, startingDstr);
+ method.invokevirtual(p(ByteList.class), "dup", sig(ByteList.class));
+ method.ldc(StringSupport.CR_7BIT);
+ method.invokestatic(p(RubyString.class), "newStringShared", sig(RubyString.class, Ruby.class, ByteList.class, int.class));
for (int i = 0; i < count; i++) {
callback.nextValue(this, null, i);

0 comments on commit 17ea768

Please sign in to comment.