Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 4a2f300d6d2d
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 2271fcabde71
Choose a head ref
  • 3 commits
  • 4 files changed
  • 1 contributor

Commits on Jun 14, 2016

  1. Copy the full SHA
    e6411c9 View commit details
  2. optimize nil.inspect by sharing the bytes returned

    ... it is used a lot e.g. 18k+ invocations on test:jruby
    kares committed Jun 14, 2016
    Copy the full SHA
    4d3dfee View commit details
  3. Copy the full SHA
    2271fca View commit details
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/RubyMatchData.java
Original file line number Diff line number Diff line change
@@ -406,9 +406,9 @@ public IRubyObject inspect() {
}
IRubyObject v = RubyRegexp.nth_match(i, this);
if (v.isNil()) {
result.cat("nil".getBytes());
result.cat(RubyNil.nilBytes); // "nil"
} else {
result.append(((RubyString)v).inspect19());
result.append(((RubyString) v).inspect(runtime));
}
}

9 changes: 7 additions & 2 deletions core/src/main/java/org/jruby/RubyNil.java
Original file line number Diff line number Diff line change
@@ -32,6 +32,7 @@
***** END LICENSE BLOCK *****/
package org.jruby;

import org.jcodings.specific.USASCIIEncoding;
import org.jruby.anno.JRubyMethod;
import org.jruby.anno.JRubyClass;
import org.jruby.compiler.Constantizable;
@@ -40,6 +41,7 @@
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.opto.OptoFactory;
import org.jruby.util.ByteList;

/**
*
@@ -156,7 +158,7 @@ public static RubyArray to_a(ThreadContext context, IRubyObject recv) {
public static RubyHash to_h(ThreadContext context, IRubyObject recv) {
return RubyHash.newSmallHash(context.runtime);
}

/** nil_inspect
*
*/
@@ -165,8 +167,11 @@ public static RubyString inspect(ThreadContext context, IRubyObject recv) {
return inspect(context.runtime);
}

static final byte[] nilBytes = new byte[] { 'n','i','l' }; // RubyString.newUSASCIIString(runtime, "nil")
private static final ByteList nil = new ByteList(nilBytes, USASCIIEncoding.INSTANCE);

static RubyString inspect(Ruby runtime) {
return RubyString.newUSASCIIString(runtime, "nil");
return RubyString.newStringShared(runtime, runtime.getString(), nil);
}

/** nil_and
18 changes: 14 additions & 4 deletions core/src/main/java/org/jruby/RubyString.java
Original file line number Diff line number Diff line change
@@ -1974,13 +1974,18 @@ private void raiseIndexOutOfString(int index) {
*
*/
@Override
@JRubyMethod(name = "inspect")
public IRubyObject inspect() {
return inspect19();
return inspect(getRuntime());
}

@JRubyMethod(name = "inspect")
final RubyString inspect(final Ruby runtime) {
return (RubyString) inspect(runtime, value).infectBy(this);
}

@Deprecated
public IRubyObject inspect19() {
return inspect19(getRuntime(), value).infectBy(this);
return inspect();
}

// MRI: rb_str_escape
@@ -2048,7 +2053,12 @@ else if (asciicompat && Encoding.isAscii(c) && (c < 0x7F && c > 31 /*ISPRINT(c)*
return result;
}

public static IRubyObject inspect19(Ruby runtime, ByteList byteList) {
@Deprecated
public static IRubyObject inspect19(final Ruby runtime, ByteList byteList) {
return inspect(runtime, byteList);
}

public static RubyString inspect(final Ruby runtime, ByteList byteList) {
Encoding enc = byteList.getEncoding();
byte bytes[] = byteList.getUnsafeBytes();
int p = byteList.getBegin();
45 changes: 22 additions & 23 deletions core/src/main/java/org/jruby/RubySymbol.java
Original file line number Diff line number Diff line change
@@ -75,7 +75,7 @@
/**
* Represents a Ruby symbol (e.g. :bar)
*/
@JRubyClass(name="Symbol")
@JRubyClass(name = "Symbol", include = "Enumerable")
public class RubySymbol extends RubyObject implements MarshalEncoding, EncodingCapable, Constantizable {
public static final long symbolHashSeedK0 = 5238926673095087190l;

@@ -144,12 +144,12 @@ public ClassIndex getNativeClassIndex() {
* @return a String representation of the symbol
*/
@Override
public String asJavaString() {
public final String asJavaString() {
return symbol;
}

@Override
public String toString() {
public final String toString() {
return symbol;
}

@@ -250,46 +250,45 @@ public Object constant() {
constant;
}

@Deprecated
@Override
public IRubyObject inspect() {
return inspect19(getRuntime().getCurrentContext());
}

public IRubyObject inspect(ThreadContext context) {
return inspect19(context.runtime);
return inspect(getRuntime());
}

@JRubyMethod(name = "inspect")
public IRubyObject inspect19(ThreadContext context) {
return inspect19(context.runtime);
public IRubyObject inspect(ThreadContext context) {
return inspect(context.runtime);
}

private final IRubyObject inspect19(Ruby runtime) {
final RubyString inspect(final Ruby runtime) {
ByteList result = new ByteList(symbolBytes.getRealSize() + 1);
result.setEncoding(symbolBytes.getEncoding());
result.append((byte)':');
result.append(symbolBytes);

RubyString str = RubyString.newString(runtime, result);
// TODO: 1.9 rb_enc_symname_p
Encoding resenc = runtime.getDefaultInternalEncoding();
if (resenc == null) {
resenc = runtime.getDefaultExternalEncoding();
}
if (resenc == null) resenc = runtime.getDefaultExternalEncoding();

RubyString str = RubyString.newString(runtime, result);

if (isPrintable() && (resenc.equals(symbolBytes.getEncoding()) || str.isAsciiOnly()) && isSymbolName19(symbol)) {
return str;
}

str = (RubyString)str.inspect19();
str = str.inspect(runtime);
ByteList bytes = str.getByteList();
bytes.set(0, ':');
bytes.set(1, '"');

return str;
}

@Deprecated
public IRubyObject inspect19(ThreadContext context) {
return inspect(context);
}

@Override
public IRubyObject to_s() {
return to_s(getRuntime());
@@ -666,7 +665,7 @@ public SymbolTable(Ruby runtime) {
// note all fields are final -- rehash creates new entries when necessary.
// as documented in java.util.concurrent.ConcurrentHashMap.java, that will
// statistically affect only a small percentage (< 20%) of entries for a given rehash.
static class SymbolEntry {
static final class SymbolEntry {
final int hash;
final String name;
final ByteList bytes;
@@ -1018,12 +1017,12 @@ public Encoding getMarshalEncoding() {
*/
public static String objectToSymbolString(IRubyObject object) {
if (object instanceof RubySymbol) {
return ((RubySymbol)object).toString();
} else if (object instanceof RubyString) {
return ((RubyString)object).getByteList().toString();
} else {
return object.convertToString().getByteList().toString();
return ((RubySymbol) object).toString();
}
if (object instanceof RubyString) {
return ((RubyString) object).getByteList().toString();
}
return object.convertToString().getByteList().toString();
}

private static class SymbolProcBody extends ContextAwareBlockBody {