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

Commits on Jan 6, 2015

  1. Clean up and align logic in String#start_with? and end_with?.

    Whitespace is your friend.
    headius committed Jan 6, 2015
    Copy the full SHA
    b110106 View commit details
  2. Copy the full SHA
    20dc9ec View commit details
  3. Copy the full SHA
    c9d8c77 View commit details
Showing with 26 additions and 11 deletions.
  1. +2 −2 core/src/main/java/org/jruby/RubyModule.java
  2. +24 −8 core/src/main/java/org/jruby/RubyString.java
  3. +0 −1 test/mri/excludes/TestModule.rb
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/RubyModule.java
Original file line number Diff line number Diff line change
@@ -2205,7 +2205,7 @@ public IRubyObject extend_object(IRubyObject obj) {
/** rb_mod_include
*
*/
@JRubyMethod(name = "include", rest = true, visibility = PRIVATE)
@JRubyMethod(name = "include", rest = true)
public RubyModule include(IRubyObject[] modules) {
ThreadContext context = getRuntime().getCurrentContext();
// MRI checks all types first:
@@ -2995,7 +2995,7 @@ public IRubyObject public_constant(ThreadContext context, IRubyObject[] rubyName
return this;
}

@JRubyMethod(name = "prepend", rest = true, visibility = PUBLIC)
@JRubyMethod(name = "prepend", rest = true)
public IRubyObject prepend(ThreadContext context, IRubyObject[] modules) {
// MRI checks all types first:
for (int i = modules.length; --i >= 0; ) {
32 changes: 24 additions & 8 deletions core/src/main/java/org/jruby/RubyString.java
Original file line number Diff line number Diff line change
@@ -3917,7 +3917,7 @@ private boolean start_with_pCommon(IRubyObject arg) {
return true;
}

if (value.getRealSize() < otherString.value.getRealSize()) return false;
if (value.getRealSize() < otherLength) return false;

return value.startsWith(otherString.value);
}
@@ -3941,20 +3941,36 @@ public IRubyObject end_with_p(ThreadContext context, IRubyObject[]args) {
}

private boolean end_with_pCommon(IRubyObject arg) {
IRubyObject tmp = arg.checkStringType();
if (tmp.isNil()) return false;
RubyString otherString = (RubyString)tmp;
int otherLength = otherString.value.getRealSize();
Ruby runtime = getRuntime();
RubyString otherString;

if (!runtime.is2_0()) {
// 1.8 and 1.9 ignores uncoercible argument
IRubyObject tmp = arg.checkStringType();
if (tmp.isNil()) return false;
otherString = (RubyString) tmp;
} else {
// 2.0+ requires coersion to succeed
otherString = arg.convertToString();
}

Encoding enc = checkEncoding(otherString);
if (value.getRealSize() < otherLength) return false;
int p = value.getBegin();
int end = p + value.getRealSize();

int otherLength = otherString.value.getRealSize();

if (otherLength == 0) {
// other is '', so return true
return true;
}

if (value.getRealSize() < otherLength) return false;

int p = value.getBegin();
int end = p + value.getRealSize();
int s = end - otherLength;

if (enc.leftAdjustCharHead(value.getUnsafeBytes(), p, s, end) != s) return false;

return value.endsWith(otherString.value);
}

1 change: 0 additions & 1 deletion test/mri/excludes/TestModule.rb
Original file line number Diff line number Diff line change
@@ -19,5 +19,4 @@
exclude :test_private_constant_with_no_args, "needs investigation"
exclude :test_private_top_methods, "needs investigation"
exclude :test_protected_singleton_method, "needs investigation"
exclude :test_public_include, "needs investigation"
exclude :test_undef, "needs investigation"