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

Commits on Feb 6, 2015

  1. Copy the full SHA
    534e7ac View commit details
  2. Copy the full SHA
    ede5c46 View commit details
5 changes: 0 additions & 5 deletions spec/truffle/tags/core/string/comparison_tags.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
fails:String#<=> with String returns -1 when self is less than other
fails:String#<=> with String returns 1 when self is greater than other
fails:String#<=> with String considers string that comes lexicographically first to be less if strings have same size
fails:String#<=> with String compares shorter string with corresponding number of first chars of longer string
fails:String#<=> with String ignores encoding difference
fails:String#<=> with String compares the indices of the encodings when the strings have identical non-ASCII-compatible bytes
fails:String#<=> returns nil if its argument provides neither #to_str nor #<=>
fails:String#<=> uses the result of calling #to_str for comparison when #to_str is defined
fails:String#<=> uses the result of calling #<=> on its argument when #<=> is defined but #to_str is not
fails:String#<=> returns nil if argument also uses an inverse comparison for <=>
Original file line number Diff line number Diff line change
@@ -122,6 +122,8 @@ public boolean equal(RubyString a, Object b) {
@CoreMethod(names = "<=>", required = 1)
public abstract static class CompareNode extends CoreMethodNode {

@Child private ToStrNode toStrNode;

public CompareNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}
@@ -134,7 +136,37 @@ public CompareNode(CompareNode prev) {
public int compare(RubyString a, RubyString b) {
notDesignedForCompilation();

return a.toString().compareTo(b.toString());
final int result = a.toString().compareTo(b.toString());

if (result < 0) {
return -1;
} else if (result > 0) {
return 1;
}

return 0;
}

@Specialization(guards = "!isRubyString(arguments[1])")
public Object compare(VirtualFrame frame, RubyString a, Object b) {
notDesignedForCompilation();

if (toStrNode == null) {
CompilerDirectives.transferToInterpreter();
toStrNode = insert(ToStrNodeFactory.create(getContext(), getSourceSection(), null));
}

try {
final RubyString coerced = toStrNode.executeRubyString(frame, b);

return compare(a, coerced);
} catch (RaiseException e) {
if (e.getRubyException().getClass().equals(getContext().getCoreLibrary().getTypeErrorClass())) {
return getContext().getCoreLibrary().getNilObject();
} else {
throw e;
}
}
}
}

Original file line number Diff line number Diff line change
@@ -943,6 +943,8 @@ public RubyClass getTimeClass() {
return timeClass;
}

public RubyClass getTypeErrorClass() { return typeErrorClass; }

public RubyClass getTrueClass() {
return trueClass;
}