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

Commits on Mar 31, 2015

  1. Copy the full SHA
    6c70997 View commit details
  2. Copy the full SHA
    850bfab View commit details
Showing with 17 additions and 62 deletions.
  1. +17 −1 truffle/src/main/java/org/jruby/truffle/nodes/core/StringNodes.java
  2. +0 −61 truffle/src/main/java/org/jruby/truffle/runtime/core/RubyString.java
Original file line number Diff line number Diff line change
@@ -860,6 +860,10 @@ public CountNode(CountNode prev) {
public int count(VirtualFrame frame, RubyString string, Object[] otherStrings) {
notDesignedForCompilation();

if (string.getByteList().getRealSize() == 0) {
return 0;
}

if (otherStrings.length == 0) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().argumentErrorEmptyVarargs(this));
@@ -876,7 +880,19 @@ private int countSlow(VirtualFrame frame, RubyString string, Object[] args) {
otherStrings[i] = toStr.executeRubyString(frame, args[i]);
}

return string.count(otherStrings);
RubyString otherStr = otherStrings[0];
Encoding enc = otherStr.getBytes().getEncoding();

final boolean[]table = new boolean[StringSupport.TRANS_SIZE + 1];
StringSupport.TrTables tables = StringSupport.trSetupTable(otherStr.getBytes(), getContext().getRuntime(), table, null, true, enc);
for (int i = 1; i < otherStrings.length; i++) {
otherStr = otherStrings[i];

enc = string.checkEncoding(otherStr, this);
tables = StringSupport.trSetupTable(otherStr.getBytes(), getContext().getRuntime(), table, tables, false, enc);
}

return StringSupport.countCommon19(string.getByteList(), getContext().getRuntime(), table, tables, enc);
}
}

Original file line number Diff line number Diff line change
@@ -65,67 +65,6 @@ public ByteList getBytes() {
return bytes;
}

public static String ljust(String string, int length, String padding) {
final StringBuilder builder = new StringBuilder();

builder.append(string);

int n = 0;

while (builder.length() < length) {
builder.append(padding.charAt(n));

n++;

if (n == padding.length()) {
n = 0;
}
}

return builder.toString();
}

public static String rjust(String string, int length, String padding) {
final StringBuilder builder = new StringBuilder();

int n = 0;

while (builder.length() + string.length() < length) {
builder.append(padding.charAt(n));

n++;

if (n == padding.length()) {
n = 0;
}
}

builder.append(string);

return builder.toString();
}

public int count(RubyString[] otherStrings) {
if (bytes.getRealSize() == 0) {
return 0;
}

RubyString otherStr = otherStrings[0];
Encoding enc = otherStr.getBytes().getEncoding();

final boolean[]table = new boolean[StringSupport.TRANS_SIZE + 1];
StringSupport.TrTables tables = StringSupport.trSetupTable(otherStr.getBytes(), getContext().getRuntime(), table, null, true, enc);
for (int i = 1; i < otherStrings.length; i++) {
otherStr = otherStrings[i];

// TODO (nirvdrum Dec. 19, 2014): This method should be encoding aware and check that the strings have compatible encodings. See non-Truffle JRuby for a more complete solution.
//enc = checkEncoding(otherStr);
tables = StringSupport.trSetupTable(otherStr.getBytes(), getContext().getRuntime(), table, tables, false, enc);
}

return StringSupport.countCommon19(getBytes(), getContext().getRuntime(), table, tables, enc);
}

@Override
@TruffleBoundary
public String toString() {