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: opal/opal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: f5f2c5cb35d1
Choose a base ref
...
head repository: opal/opal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: a00188702fd1
Choose a head ref
  • 5 commits
  • 3 files changed
  • 2 contributors

Commits on Jul 18, 2015

  1. Simplify Array#& implementation (follow MRI's algo)

    Performance profile is unaffected by this change:
    $ bundle exec rake bench:report
    Benchmark                                   Opal1  Opal2
    benchmark/bm_array_intersection_numbers.rb  1.342  1.344
    benchmark/bm_array_intersection_objects.rb  2.595  2.439
    benchmark/bm_array_intersection_strings.rb  0.795  0.787
    (Opal1 = master branch, Opal2 = array branch)
    vais committed Jul 18, 2015
    Copy the full SHA
    6d172a5 View commit details
  2. Array#| acts as if using an intermediate hash to collect values

    Performance not affected:
    $ bundle exec rake bench:report
    Benchmark                            Opal1  Opal2
    benchmark/bm_array_union_numbers.rb  2.136  2.135
    benchmark/bm_array_union_objects.rb  4.362  4.568
    benchmark/bm_array_union_strings.rb  1.660  1.675
    (Opal1 = master branch, Opal2 = array branch)
    vais committed Jul 18, 2015
    Copy the full SHA
    96068c1 View commit details
  3. Array#- doesn't remove an item with the same hash but not #eql?

    Array#- removes an item identified as equivalent via #hash and #eql?
    
    Performance not affected:
    $ bundle exec rake bench:report
    Benchmark                            Opal1  Opal2
    benchmark/bm_array_minus_numbers.rb  1.380  1.367
    benchmark/bm_array_minus_objects.rb  2.468  2.474
    benchmark/bm_array_minus_strings.rb  0.814  0.814
    (Opal1 = master branch, Opal2 = array branch)
    vais committed Jul 18, 2015
    Copy the full SHA
    570a482 View commit details
  4. Array#uniq uses eql? semantics

    Performance is not affected:
    $ bundle exec rake bench:report
    Benchmark                                Opal1  Opal2
    benchmark/bm_array_uniq_bang_numbers.rb  0.605  0.579
    benchmark/bm_array_uniq_bang_objects.rb  1.073  1.270
    benchmark/bm_array_uniq_bang_strings.rb  0.358  0.469
    benchmark/bm_array_uniq_numbers.rb       0.554  0.539
    benchmark/bm_array_uniq_objects.rb       1.108  1.302
    benchmark/bm_array_uniq_strings.rb       0.358  0.456
    (Opal1 = master branch, Opal2 = array branch)
    vais committed Jul 18, 2015
    Copy the full SHA
    c6f0b6c View commit details
  5. Merge pull request #1014 from vais/array

    Fix Array#|, Array#-, and Array#uniq RubySpec failures
    elia committed Jul 18, 2015

    Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    a001887 View commit details
Showing with 32 additions and 31 deletions.
  1. +30 −25 opal/corelib/array.rb
  2. +0 −6 spec/filters/bugs/array.rb
  3. +2 −0 spec/filters/unsupported/array.rb
55 changes: 30 additions & 25 deletions opal/corelib/array.rb
Original file line number Diff line number Diff line change
@@ -74,30 +74,21 @@ def &(other)

%x{
var result = [],
other_items = {},
chosen_items = {},
i, length,
item, hash;
others = {},
i, length, item, hash;
for (i = 0, length = other.length; i < length; i++) {
item = other[i];
other_items[item.$hash()] = item;
others[item.$hash()] = item;
}
for (i = 0, length = self.length; i < length; i++) {
item = self[i];
hash = item.$hash();
if (!other_items.hasOwnProperty(hash)) {
continue;
}
if (chosen_items.hasOwnProperty(hash)) {
continue;
}
if (!#{`item`.eql?(`other_items[hash]`)}) {
continue;
if (others.hasOwnProperty(hash) && #{`item`.eql?(`others[hash]`)}) {
delete others[hash];
result.push(item);
}
chosen_items[hash] = true;
result.push(item);
}
return result;
@@ -120,7 +111,7 @@ def |(other)
item_hash = item.$hash();
if (!seen.hasOwnProperty(item_hash)) {
seen[item_hash] = true;
seen[item_hash] = item;
result.push(item);
}
}
@@ -129,11 +120,16 @@ def |(other)
item = other[i];
item_hash = item.$hash();
if (!seen.hasOwnProperty(item_hash)) {
seen[item_hash] = true;
if (seen.hasOwnProperty(item_hash)) {
if (!#{`item`.eql?(`seen[item_hash]`)}) {
result.push(item);
}
} else {
seen[item_hash] = item;
result.push(item);
}
}
return result;
}
end
@@ -184,18 +180,24 @@ def -(other)

%x{
var seen = {},
result = [], i, length, item;
result = [], i, length, item, hash;
for (i = 0, length = other.length; i < length; i++) {
seen[other[i].$hash()] = true;
item = other[i];
hash = item.$hash();
seen[hash] = item;
}
for (i = 0, length = self.length; i < length; i++) {
item = self[i];
hash = item.$hash();
if (!seen.hasOwnProperty(item.$hash())) {
result.push(item);
if (seen.hasOwnProperty(hash)) {
if (#{`item`.eql?(`seen[hash]`)}) { continue; }
if (item.$object_id() === seen[hash].$object_id()) { continue; }
}
result.push(item);
}
return result;
@@ -1966,10 +1968,13 @@ def uniq
item = self[i];
hash = item.$hash();
if (!seen.hasOwnProperty(hash)) {
seen[hash] = true;
result.push(item);
if (seen.hasOwnProperty(hash)) {
if (#{`item`.eql?(`seen[hash]`)}) { continue; }
if (item.$object_id() === seen[hash].$object_id()) { continue; }
}
seen[hash] = item;
result.push(item);
}
return result;
6 changes: 0 additions & 6 deletions spec/filters/bugs/array.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
opal_filter "Array" do
fails "Array#- doesn't remove an item with the same hash but not #eql?"
fails "Array#- removes an item identified as equivalent via #hash and #eql?"
fails "Array#<=> properly handles recursive arrays"
fails "Array#clone copies singleton methods"
fails "Array#combination when no block is given returned Enumerator size returns 0 when the number of combinations is < 0"
@@ -76,15 +74,11 @@
fails "Array#sort_by! sorts array in place by passing each element to the given block"
fails "Array#sort_by! when no block is given returned Enumerator size returns the enumerable size"
fails "Array#uniq compares elements based on the value returned from the block"
fails "Array#uniq compares elements first with hash"
fails "Array#uniq compares elements with matching hash codes with #eql?"
fails "Array#uniq handles nil and false like any other values"
fails "Array#uniq uses eql? semantics"
fails "Array#uniq yields items in order"
fails "Array#uniq! compares elements based on the value returned from the block"
fails "Array#uniq! properly handles recursive arrays"
fails "Array#zip fills nil when the given enumereator is shorter than self"
fails "Array#zip stops at own size when given an infinite enumerator"
fails "Array#| acts as if using an intermediate hash to collect values"
fails "Array.[] can unpack 2 or more nested referenced array"
end
2 changes: 2 additions & 0 deletions spec/filters/unsupported/array.rb
Original file line number Diff line number Diff line change
@@ -164,6 +164,8 @@
fails "Array#to_s with encoding returns a US-ASCII string for an empty Array"
fails "Array#to_s with encoding use US-ASCII encoding if the default external encoding is not ascii compatible"
fails "Array#to_s with encoding use the default external encoding if it is ascii compatible"
fails "Array#uniq compares elements with matching hash codes with #eql?" #RubySpec uses taint, which is not supported on Opal.
fails "Array#uniq uses eql? semantics" #RubySpec expects 1.0 and 1 to be seen as different, which is not supported on Opal.
fails "Array#uniq! doesn't yield to the block on a frozen array"
fails "Array#uniq! raises a RuntimeError on a frozen array when the array is modified"
fails "Array#uniq! raises a RuntimeError on a frozen array when the array would not be modified"