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: a2bc9a3a0dee
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 0b7b181cc682
Choose a head ref
  • 2 commits
  • 5 files changed
  • 1 contributor

Commits on Jul 23, 2018

  1. Copy the full SHA
    77a768c View commit details
  2. Copy the full SHA
    0b7b181 View commit details
Original file line number Diff line number Diff line change
@@ -76,7 +76,7 @@ public static MethodHandle generate(final int size) {
if (h != null) return h;

final String clsPath = "org/jruby/runtime/scopes/DynamicScope" + size;
final String clsName = clsPath.replaceAll("/", ".");
final String clsName = clsPath.replace('/', '.');

// try to load the class, in case we have parallel generation happening
Class p;
@@ -341,7 +341,7 @@ private static Class loadClass(JiteClass jiteClass) throws ClassNotFoundExceptio
}

private static String classNameFromJiteClass(JiteClass jiteClass) {
return jiteClass.getClassName().replaceAll("/", ".");
return jiteClass.getClassName().replace('/', '.');
}

private static String[] varList(int size) {
Original file line number Diff line number Diff line change
@@ -88,7 +88,7 @@ public static ObjectAllocator specializeForVariables(RubyClass klass, Set<String
synchronized (LOADER) {
try {
// try loading class without generating
specialized = LOADER.loadClass(clsPath.replaceAll("/", "."));
specialized = LOADER.loadClass(clsPath.replace('/', '.'));
} catch (ClassNotFoundException cnfe) {
// generate specialized class
specialized = generateInternal(foundVariables.size(), clsPath);
88 changes: 36 additions & 52 deletions core/src/main/java/org/jruby/util/ConvertBytes.java
Original file line number Diff line number Diff line change
@@ -4,10 +4,7 @@
import java.nio.ByteBuffer;
import java.util.Arrays;

import org.jruby.Ruby;
import org.jruby.RubyBignum;
import org.jruby.RubyInteger;
import org.jruby.RubyString;
import org.jruby.*;
import org.jruby.runtime.builtin.IRubyObject;

public class ConvertBytes {
@@ -555,21 +552,19 @@ private long stringToLong(int nptr, int[] endptr, int base) {
}

public RubyInteger byteListToInum() {
if(str == null) {
if(badcheck) invalidString("Integer");

return runtime.newFixnum(0);
if (str == null) {
if (badcheck) invalidString("Integer");
return RubyFixnum.zero(runtime);
}

ignoreLeadingWhitespace();

boolean sign = getSign();

if(beg < end) {
if (beg < end) {
if(data[beg] == '+' || data[beg] == '-') {
if(badcheck) invalidString("Integer");

return runtime.newFixnum(0);
if (badcheck) invalidString("Integer");
return RubyFixnum.zero(runtime);
}
}

@@ -580,38 +575,37 @@ public RubyInteger byteListToInum() {
squeezeZeroes();

byte c = 0;
if(beg < end) {
if (beg < end) {
c = data[beg];
}
c = convertDigit(c);
if(c < 0 || c >= base) {
if(badcheck) invalidString("Integer");

return runtime.newFixnum(0);
if (c < 0 || c >= base) {
if (badcheck) invalidString("Integer");
return RubyFixnum.zero(runtime);
}

if (base <= 10) {
len *= (trailingLength());
len *= trailingLength();
} else {
len *= (end- beg);
len *= (end - beg);
}

if(len < Long.SIZE-1) {
int[] endPlace = new int[]{beg};
if (len < Long.SIZE-1) {
int[] endPlace = new int[] { beg };
long val = stringToLong(beg, endPlace, base);
if(endPlace[0] < end && data[endPlace[0]] == '_') {
if (endPlace[0] < end && data[endPlace[0]] == '_') {
return bigParse(len, sign);
}
if(badcheck) {
if(endPlace[0] == beg) {
if (badcheck) {
if (endPlace[0] == beg) {
invalidString("Integer"); // no number
}

while(isSpace(endPlace[0])) {
while (isSpace(endPlace[0])) {
endPlace[0]++;
}

if(endPlace[0] < end) {
if (endPlace[0] < end) {
invalidString("Integer"); // trailing garbage
}
}
@@ -631,11 +625,11 @@ private int trailingLength() {
}

private RubyInteger bigParse(int len, boolean sign) {
if(badcheck && beg < end && data[beg] == '_') {
if (badcheck && beg < end && data[beg] == '_') {
invalidString("Integer");
}

char[] result = new char[end- beg];
char[] result = new char[end - beg];
int resultIndex = 0;

byte nondigit = -1;
@@ -644,61 +638,51 @@ private RubyInteger bigParse(int len, boolean sign) {
{
while(beg < end) {
byte c = data[beg++];
byte cx = c;
if(c == '_') {
if(nondigit != -1) {
if(badcheck) {
invalidString("Integer");
}
char cx = (char) c;
if (c == '_') {
if (nondigit != -1) {
if (badcheck) invalidString("Integer");
break;
}
nondigit = c;
continue;
} else if((c = convertDigit(c)) < 0) {
break;
}
if(c >= base) {
break;
}
if (c >= base) break;
nondigit = -1;
result[resultIndex++] = (char)cx;
result[resultIndex++] = cx;
}

if(resultIndex == 0) return runtime.newFixnum(0);
if (resultIndex == 0) return RubyFixnum.zero(runtime);

int tmpStr = beg;
if (badcheck) {
// no beg-- here because we don't null-terminate strings
if (str.getBegin()+1 < tmpStr && data[tmpStr-1] == '_') invalidString("Integer");
while (tmpStr < end && Character.isWhitespace(data[tmpStr])) tmpStr++;
if (tmpStr < end) {
invalidString("Integer");
}
if (tmpStr < end) invalidString("Integer");

}
}

String s = new String(result, 0, resultIndex);
BigInteger z = (base == 10) ? stringToBig(s) : new BigInteger(s, base);
if(!sign) z = z.negate();
if (!sign) z = z.negate();

if(badcheck) {
if(str.getBegin() + 1 < beg && data[beg -1] == '_') {
invalidString("Integer");
}
while(beg < end && isSpace(beg)) {
beg++;
}
if(beg < end) {
if (badcheck) {
if (str.getBegin() + 1 < beg && data[beg -1] == '_') {
invalidString("Integer");
}
while(beg < end && isSpace(beg)) beg++;
if (beg < end) invalidString("Integer");
}

return RubyBignum.bignorm(runtime, z);
}

private BigInteger stringToBig(String str) {
str = str.replaceAll("_", "");
str = StringSupport.delete(str, '_');
int size = str.length();
int nDigits = 512;
if (size < nDigits) nDigits = size;
6 changes: 3 additions & 3 deletions core/src/main/java/org/jruby/util/ConvertDouble.java
Original file line number Diff line number Diff line change
@@ -102,15 +102,15 @@ private boolean stopParsing() {
return true;
}

private boolean isDigit(byte b) {
private static boolean isDigit(byte b) {
return b >= '0' && b <= '9';
}

private boolean isExponent(byte b) {
private static boolean isExponent(byte b) {
return b == 'e' || b == 'E';
}

private boolean isWhitespace(byte b) {
private static boolean isWhitespace(byte b) {
return b == ' ' || (b <= 13 && b >= 9 && b != 11);
}

36 changes: 36 additions & 0 deletions core/src/main/java/org/jruby/util/StringSupport.java
Original file line number Diff line number Diff line change
@@ -171,6 +171,42 @@ public static CharSequence concat(final CharSequence str1, final CharSequence st
return new StringBuilder(str1.length() + str2.length()).append(str1).append(str2);
}

public static String delete(final String str, final char c) { // str.replaceAll(c.toString(), "")
char[] ary = null; int end = 0, s = 0;
for (int i = 0; i < str.length(); i++) {
if (str.charAt(i) == c) {
if (ary == null) {
ary = new char[str.length() - 1];
}
end = copy(str, s, i - s, ary, end);
s = i + 1;
}
}
return ary == null ? str : new String(ary, 0, end);
}

private static int copy(final String str, final int soff, final int slen, final char[] dest, int doff) {
switch(slen) {
case 0:
break;
case 1:
dest[doff++] = str.charAt(soff);
break;
case 2:
dest[doff++] = str.charAt(soff);
dest[doff++] = str.charAt(soff + 1);
break;
case 3:
dest[doff++] = str.charAt(soff);
dest[doff++] = str.charAt(soff + 1);
dest[doff++] = str.charAt(soff + 2);
break;
default:
for (int s = soff; s < slen; s++) dest[doff++] = str.charAt(s);
}
return doff;
}

public static String codeRangeAsString(int codeRange) {
switch (codeRange) {
case CR_UNKNOWN: return "unknown";