Skip to content

Commit

Permalink
Showing 2 changed files with 13 additions and 8 deletions.
7 changes: 2 additions & 5 deletions core/src/main/java/org/jruby/RubyString.java
Original file line number Diff line number Diff line change
@@ -4491,9 +4491,6 @@ public IRubyObject strip_bang19(ThreadContext context) {
return left.isNil() && right.isNil() ? context.runtime.getNil() : this;
}

/** rb_str_count
*
*/
public IRubyObject count(ThreadContext context) {
return count19(context);
}
@@ -4542,7 +4539,7 @@ public IRubyObject count19(ThreadContext context, IRubyObject arg) {

final boolean[] table = new boolean[StringSupport.TRANS_SIZE + 1];
StringSupport.TrTables tables = StringSupport.trSetupTable(countValue, runtime, table, null, true, enc);
return runtime.newFixnum(StringSupport.countCommon19(value, runtime, table, tables, enc));
return runtime.newFixnum(StringSupport.strCount(value, runtime, table, tables, enc));
}

// MRI: rb_str_count for arity > 1, first half
@@ -4563,7 +4560,7 @@ public IRubyObject count19(ThreadContext context, IRubyObject[] args) {
tables = StringSupport.trSetupTable(countStr.value, runtime, table, tables, false, enc);
}

return runtime.newFixnum(StringSupport.countCommon19(value, runtime, table, tables, enc));
return runtime.newFixnum(StringSupport.strCount(value, runtime, table, tables, enc));
}

/** rb_str_delete / rb_str_delete_bang
14 changes: 11 additions & 3 deletions core/src/main/java/org/jruby/util/StringSupport.java
Original file line number Diff line number Diff line change
@@ -418,6 +418,7 @@ public static int preciseCodePoint(Encoding enc, byte[]bytes, int p, int end) {
return -1;
}

@SuppressWarnings("deprecation")
@SuppressWarnings("deprecation")
public static int utf8Nth(byte[]bytes, int p, int e, int nth) {
// FIXME: Missing our UNSAFE impl because it was doing the wrong thing: See GH #1986
@@ -868,16 +869,16 @@ public static boolean isEVStr(int c) {
/**
* rb_str_count
*/

public static int countCommon19(ByteList str, Ruby runtime, boolean[] table, TrTables tables, Encoding enc) {
public static int strCount(ByteList str, Ruby runtime, boolean[] table, TrTables tables, Encoding enc) {
final byte[] bytes = str.getUnsafeBytes();
int p = str.getBegin();
final int end = p + str.getRealSize();
final boolean asciiCompat = enc.isAsciiCompatible();

int count = 0;
while (p < end) {
int c;
if (enc.isAsciiCompatible() && (c = bytes[p] & 0xff) < 0x80) {
if (asciiCompat && (c = bytes[p] & 0xff) < 0x80) {
if (table[c]) count++;
p++;
} else {
@@ -891,6 +892,13 @@ public static int countCommon19(ByteList str, Ruby runtime, boolean[] table, TrT
return count;
}

/**
* @deprecated renamed to {@link #strCount(ByteList, Ruby, boolean[], TrTables, Encoding)}
*/
public static int countCommon19(ByteList str, Ruby runtime, boolean[] table, TrTables tables, Encoding enc) {
return strCount(str, runtime, table, tables, enc);
}

// MRI: rb_str_rindex
public static int rindex(ByteList source, int sourceChars, int subChars, int pos, CodeRangeable subStringCodeRangeable, Encoding enc) {
if (subStringCodeRangeable.scanForCodeRange() == CR_BROKEN) return -1;

0 comments on commit aeaf963

Please sign in to comment.