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

Commits on Jun 24, 2016

  1. Copy the full SHA
    36f13e1 View commit details
  2. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    4bac59d View commit details
  3. [Truffle] Simplified encoding check a bit.

    I believe the only reason for checking if the encoding is ASCII compatible is to short-circuit a code range scan in other implementations. With ropes, however, we eagerly calculate the code range so we don't need to short-circuit.
    nirvdrum committed Jun 24, 2016
    Copy the full SHA
    4912a97 View commit details
  4. Copy the full SHA
    65822b9 View commit details
  5. [Truffle] Added a fast case for Encoding.compatible? on any two argum…

    …ents with the same encoding.
    nirvdrum committed Jun 24, 2016
    Copy the full SHA
    31f0076 View commit details
  6. Copy the full SHA
    79b8610 View commit details
  7. Copy the full SHA
    ae00483 View commit details
  8. Copy the full SHA
    8e78cde View commit details
  9. Copy the full SHA
    dc9ea30 View commit details
  10. [Truffle] Removed lazy node loading.

    We need this node for every specialization now, so no need to for the lazy pattern.
    nirvdrum committed Jun 24, 2016
    Copy the full SHA
    2273438 View commit details
  11. [Truffle] Removed useless identical encoding check.

    This check is performed in a guard, so we don't need to do it again here.
    nirvdrum committed Jun 24, 2016
    Copy the full SHA
    94c3752 View commit details
  12. Copy the full SHA
    77c183c View commit details
  13. [Truffle] Removed useless identical encoding check.

    This check is performed in a guard, so we don't need to do it again here.
    nirvdrum committed Jun 24, 2016
    Copy the full SHA
    663e850 View commit details
  14. Copy the full SHA
    572c1ad View commit details
  15. Copy the full SHA
    1c4dedb View commit details
  16. [Truffle] Removed useless identical encoding check.

    This check is performed in a guard, so we don't need to do it again here.
    nirvdrum committed Jun 24, 2016
    Copy the full SHA
    107e384 View commit details
  17. Copy the full SHA
    f14a9a9 View commit details
  18. Removed some dead code.

    nirvdrum committed Jun 24, 2016
    Copy the full SHA
    e9a4634 View commit details
32 changes: 0 additions & 32 deletions core/src/main/java/org/jruby/RubyEncoding.java
Original file line number Diff line number Diff line change
@@ -166,38 +166,6 @@ public static Encoding areCompatible(IRubyObject obj1, IRubyObject obj2) {
return null;
}

public static Encoding areCompatible(CodeRangeable obj1, CodeRangeable obj2) {
Encoding enc1 = obj1.getByteList().getEncoding();
Encoding enc2 = obj2.getByteList().getEncoding();

if (enc1 == null || enc2 == null) return null;
if (enc1 == enc2) return enc1;

if (obj2.getByteList().getRealSize() == 0) return enc1;
if (obj1.getByteList().getRealSize() == 0) {
return enc1.isAsciiCompatible() && StringSupport.isAsciiOnly(obj2) ? enc1 : enc2;
}

if (!enc1.isAsciiCompatible() || !enc2.isAsciiCompatible()) return null;

int cr1 = obj1.scanForCodeRange();
int cr2 = obj2.scanForCodeRange();

return areCompatible(enc1, cr1, enc2, cr2);
}

public static Encoding areCompatible(Encoding enc1, Encoding enc2) {
if (enc1 == null || enc2 == null) return null;
if (enc1 == enc2) return enc1;

if (!enc1.isAsciiCompatible() || !enc2.isAsciiCompatible()) return null;

if (enc2 instanceof USASCIIEncoding) return enc1;
if (enc1 instanceof USASCIIEncoding) return enc2;

return null;
}

// last block in rb_enc_compatible
public static Encoding areCompatible(Encoding enc1, int cr1, Encoding enc2, int cr2) {
if (cr1 != cr2) {
67 changes: 67 additions & 0 deletions spec/ruby/core/encoding/compatible_spec.rb
Original file line number Diff line number Diff line change
@@ -126,6 +126,42 @@
Encoding.compatible?(@str, @str).should == Encoding::UTF_8
end
end

describe "when the first String is empty and the second is not" do
describe "and the first's Encoding is ASCII compatible" do
before :each do
@str = "".force_encoding("utf-8")
end

it "returns the first's encoding when the second String is ASCII only" do
Encoding.compatible?(@str, "def".encode("us-ascii")).should == Encoding::UTF_8
end

it "returns the second's encoding when the second String is not ASCII only" do
Encoding.compatible?(@str, "def".encode("utf-32le")).should == Encoding::UTF_32LE
end
end

describe "when the first's Encoding is not ASCII compatible" do
before :each do
@str = "".force_encoding Encoding::UTF_7
end

it "returns the second string's encoding" do
Encoding.compatible?(@str, "def".encode("us-ascii")).should == Encoding::US_ASCII
end
end
end

describe "when the second String is empty" do
before :each do
@str = "abc".force_encoding("utf-7")
end

it "returns the first Encoding" do
Encoding.compatible?(@str, "").should == Encoding::UTF_7
end
end
end

describe "Encoding.compatible? String, Regexp" do
@@ -174,6 +210,37 @@
end
end

describe "Encoding.compatible? String, Encoding" do
it "returns nil if the String's encoding is not ASCII compatible" do
Encoding.compatible?("abc".encode("utf-32le"), Encoding::US_ASCII).should be_nil
end

it "returns nil if the Encoding is not ASCII compatible" do
Encoding.compatible?("abc".encode("us-ascii"), Encoding::UTF_32LE).should be_nil
end

it "returns the String's encoding if the Encoding is US-ASCII" do
[ [Encoding, "\xff", Encoding::ASCII_8BIT],
[Encoding, "\u3042".encode("utf-8"), Encoding::UTF_8],
[Encoding, "\xa4\xa2".force_encoding("euc-jp"), Encoding::EUC_JP],
[Encoding, "\x82\xa0".force_encoding("shift_jis"), Encoding::Shift_JIS],
].should be_computed_by(:compatible?, Encoding::US_ASCII)
end

it "returns the Encoding if the String's encoding is ASCII compatible and the String is ASCII only" do
str = "abc".encode("utf-8")

Encoding.compatible?(str, Encoding::ASCII_8BIT).should == Encoding::ASCII_8BIT
Encoding.compatible?(str, Encoding::UTF_8).should == Encoding::UTF_8
Encoding.compatible?(str, Encoding::EUC_JP).should == Encoding::EUC_JP
Encoding.compatible?(str, Encoding::Shift_JIS).should == Encoding::Shift_JIS
end

it "returns nil if the String's encoding is ASCII compatible but the string is not ASCII only" do
Encoding.compatible?("\u3042".encode("utf-8"), Encoding::ASCII_8BIT).should be_nil
end
end

describe "Encoding.compatible? Regexp, String" do
it "returns US-ASCII if both are US-ASCII" do
str = "abc".force_encoding("us-ascii")
6 changes: 0 additions & 6 deletions spec/truffle/tags/core/encoding/compatible_tags.txt

This file was deleted.

1 change: 1 addition & 0 deletions test/truffle/compiler/pe/core/encoding_pe.rb
Original file line number Diff line number Diff line change
@@ -15,3 +15,4 @@
example "Encoding.compatible?('abc', 'def')", Encoding::UTF_8
example "Encoding.compatible?(Encoding::UTF_8, Encoding::US_ASCII)", Encoding::UTF_8
example "Encoding.compatible?(Encoding::UTF_8, Encoding::ASCII_8BIT)", nil
example "Encoding.compatible?('abc', Encoding::US_ASCII)", Encoding::UTF_8
Original file line number Diff line number Diff line change
@@ -9,11 +9,13 @@
*/
package org.jruby.truffle.core.cast;

import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.dsl.NodeChild;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.object.DynamicObject;
import org.jcodings.Encoding;
import org.jruby.truffle.Layouts;
import org.jruby.truffle.core.encoding.EncodingOperations;
import org.jruby.truffle.core.string.StringOperations;
import org.jruby.truffle.language.RubyNode;

@@ -46,7 +48,14 @@ public Encoding regexpToEncoding(DynamicObject value) {

@Specialization(guards = "isRubyEncoding(value)")
public Encoding rubyEncodingToEncoding(DynamicObject value) {
return Layouts.ENCODING.getEncoding(value);
// While we have a Ruby encoding object, the jcodings encoding it represents might not have been loaded yet.
// So, we can't simply use one of the layout helpers. We need to potentially load the encoding from the
// jcodings database.
return EncodingOperations.getEncoding(value);
}

@Fallback
public Encoding failure(Object value) {
return null;
}
}
Loading