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

Commits on Feb 17, 2016

  1. Copy the full SHA
    53c2c85 View commit details
  2. generic JavaMethodN call with [] args should delegate to correct arit…

    …y (due overriders)
    
    fixes #3668
    kares committed Feb 17, 2016
    Copy the full SHA
    59db950 View commit details
  3. Copy the full SHA
    c81b335 View commit details
Showing with 49 additions and 15 deletions.
  1. +14 −13 core/src/main/java/org/jruby/RubyString.java
  2. +14 −2 core/src/main/java/org/jruby/internal/runtime/methods/JavaMethod.java
  3. +21 −0 test/test_string.rb
27 changes: 14 additions & 13 deletions core/src/main/java/org/jruby/RubyString.java
Original file line number Diff line number Diff line change
@@ -6484,14 +6484,14 @@ public IRubyObject squeeze19(ThreadContext context) {
return str;
}

@JRubyMethod(name = "squeeze", compat = RUBY1_9)
@JRubyMethod(name = "squeeze", required = 1, compat = RUBY1_9)
public IRubyObject squeeze19(ThreadContext context, IRubyObject arg) {
RubyString str = strDup(context.runtime);
str.squeeze_bang19(context, arg);
return str;
}

@JRubyMethod(name = "squeeze", rest = true, compat = RUBY1_9)
@JRubyMethod(name = "squeeze", required = 2, rest = true, compat = RUBY1_9)
public IRubyObject squeeze19(ThreadContext context, IRubyObject[] args) {
RubyString str = strDup(context.runtime);
str.squeeze_bang19(context, args);
@@ -6500,11 +6500,12 @@ public IRubyObject squeeze19(ThreadContext context, IRubyObject[] args) {

@JRubyMethod(name = "squeeze!", compat = RUBY1_9)
public IRubyObject squeeze_bang19(ThreadContext context) {
Ruby runtime = context.runtime;
if (value.getRealSize() == 0) {
modifyCheck();
return runtime.getNil();
return context.nil;
}
final Ruby runtime = context.runtime;

final boolean squeeze[] = new boolean[TRANS_SIZE];
for (int i=0; i<TRANS_SIZE; i++) squeeze[i] = true;

@@ -6516,13 +6517,13 @@ public IRubyObject squeeze_bang19(ThreadContext context) {
}
}

@JRubyMethod(name = "squeeze!", compat = RUBY1_9)
@JRubyMethod(name = "squeeze!", required = 1, compat = RUBY1_9)
public IRubyObject squeeze_bang19(ThreadContext context, IRubyObject arg) {
Ruby runtime = context.runtime;
if (value.getRealSize() == 0) {
modifyCheck();
return runtime.getNil();
return context.nil;
}
final Ruby runtime = context.runtime;

RubyString otherStr = arg.convertToString();
final boolean squeeze[] = new boolean[TRANS_SIZE + 1];
@@ -6537,29 +6538,29 @@ public IRubyObject squeeze_bang19(ThreadContext context, IRubyObject arg) {

}

@JRubyMethod(name = "squeeze!", rest = true, compat = RUBY1_9)
@JRubyMethod(name = "squeeze!", rest = true, required = 2, compat = RUBY1_9)
public IRubyObject squeeze_bang19(ThreadContext context, IRubyObject[] args) {
Ruby runtime = context.runtime;
if (value.getRealSize() == 0) {
modifyCheck();
return runtime.getNil();
return context.nil;
}
final Ruby runtime = context.runtime;

RubyString otherStr = args[0].convertToString();
Encoding enc = checkEncoding(otherStr);
final boolean squeeze[] = new boolean[TRANS_SIZE + 1];
TrTables tables = otherStr.trSetupTable(runtime, squeeze, null, true, enc);

boolean singlebyte = singleByteOptimizable() && otherStr.singleByteOptimizable();
boolean singleByte = singleByteOptimizable() && otherStr.singleByteOptimizable();
for (int i=1; i<args.length; i++) {
otherStr = args[i].convertToString();
enc = checkEncoding(otherStr);
singlebyte = singlebyte && otherStr.singleByteOptimizable();
singleByte = singleByte && otherStr.singleByteOptimizable();
tables = otherStr.trSetupTable(runtime, squeeze, tables, false, enc);
}

modifyAndKeepCodeRange();
if (singlebyte) {
if (singleByte) {
return squeezeCommon(runtime, squeeze); // 1.8
} else {
return squeezeCommon19(runtime, squeeze, tables, enc, true);
Original file line number Diff line number Diff line change
@@ -675,9 +675,21 @@ public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule claz
return call(context, self, clazz, name, new IRubyObject[] {arg0, arg1, arg2});
}

public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args, Block block) {
return call(context, self, clazz, name, args);
public final IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args, Block block) {
switch (args.length) {
// still delegate to different arity calls as they might get overriden e.g. for native
// JRuby methods that use overloading for different kind arity of received arguments !
case 0:
return call(context, self, clazz, name);
case 1:
return call(context, self, clazz, name, args[0]);
case 2:
return call(context, self, clazz, name, args[0], args[1]);
default:
return call(context, self, clazz, name, args);
}
}

}


21 changes: 21 additions & 0 deletions test/test_string.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,30 @@
require 'test/unit'

class TestString < Test::Unit::TestCase

# JRUBY-4987
def test_paragraph
# raises ArrayIndexOutOfBoundsException in 1.5.1
assert_equal ["foo\n"], "foo\n".lines('').to_a
end

def test_try_squeeze
' '.squeeze
try ' ', :squeeze # ArrayIndexOutOfBoundsException
end

private

def try(obj, *a, &b) # ~ AS 4.2
if a.empty? && block_given?
if b.arity == 0
obj.instance_eval(&b)
else
yield obj
end
else
obj.public_send(*a, &b)
end
end

end