Skip to content

Commit

Permalink
no more special case intern-ing String +/- (binary) vals in Ruby 2.5
Browse files Browse the repository at this point in the history
  • Loading branch information
kares committed May 8, 2018
1 parent 223d253 commit 89183d0
Showing 1 changed file with 10 additions and 32 deletions.
42 changes: 10 additions & 32 deletions core/src/main/java/org/jruby/RubyString.java
Expand Up @@ -142,11 +142,6 @@ public class RubyString extends RubyObject implements EncodingCapable, MarshalEn

private ByteList value;

private static final String[][] opTable19 = {
{ "+", "+(binary)" },
{ "-", "-(binary)" }
};

public static RubyClass createStringClass(Ruby runtime) {
RubyClass stringClass = runtime.defineClass("String", runtime.getObject(), STRING_ALLOCATOR);
runtime.setString(stringClass);
Expand Down Expand Up @@ -5800,47 +5795,30 @@ public IRubyObject each_grapheme_cluster(ThreadContext context, Block block) {
/** rb_str_intern
*
*/
private RubySymbol to_sym() {
RubySymbol specialCaseIntern = checkSpecialCasesIntern(value);
if (specialCaseIntern != null) return specialCaseIntern;
@JRubyMethod(name = {"to_sym", "intern"})
public RubySymbol intern() {
final Ruby runtime = getRuntime();

if (scanForCodeRange() == CR_BROKEN) {
throw getRuntime().newEncodingError("invalid symbol in encoding " + getEncoding() + " :" + inspect());
throw runtime.newEncodingError("invalid symbol in encoding " + getEncoding() + " :" + inspect());
}

RubySymbol symbol = getRuntime().getSymbolTable().getSymbol(value);
RubySymbol symbol = runtime.getSymbolTable().getSymbol(value);
if (symbol.getBytes() == value) shareLevel = SHARE_LEVEL_BYTELIST;
return symbol;
}

private RubySymbol checkSpecialCasesIntern(ByteList value) {
String[][] opTable = opTable19;

for (int i = 0; i < opTable.length; i++) {
String op = opTable[i][1];
if (value.toString().equals(op)) {
return getRuntime().getSymbolTable().getSymbol(opTable[i][0]);
}
}

return null;
}

@JRubyMethod(name = {"to_sym", "intern"})
public RubySymbol intern() {
return to_sym();
}

@Deprecated
public RubySymbol intern19() {
return intern();
}

@JRubyMethod
public IRubyObject ord(ThreadContext context) {
Ruby runtime = context.runtime;
return RubyFixnum.newFixnum(runtime, codePoint(runtime, EncodingUtils.STR_ENC_GET(this), value.getUnsafeBytes(), value.getBegin(),
value.getBegin() + value.getRealSize()));
final Ruby runtime = context.runtime;
final ByteList value = this.value;
return RubyFixnum.newFixnum(runtime, codePoint(runtime, EncodingUtils.getEncoding(value),
value.getUnsafeBytes(), value.getBegin(), value.getBegin() + value.getRealSize()));
}

@JRubyMethod
Expand All @@ -5856,7 +5834,7 @@ public IRubyObject sum(ThreadContext context, IRubyObject arg) {
public IRubyObject sumCommon(ThreadContext context, long bits) {
Ruby runtime = context.runtime;

byte[]bytes = value.getUnsafeBytes();
byte[] bytes = value.getUnsafeBytes();
int p = value.getBegin();
int len = value.getRealSize();
int end = p + len;
Expand Down

0 comments on commit 89183d0

Please sign in to comment.