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

Commits on May 31, 2016

  1. Copy the full SHA
    fdb8373 View commit details
  2. Copy the full SHA
    bece4dc View commit details
42 changes: 42 additions & 0 deletions spec/truffle/specs/truffle/array/steal_storage.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. This
# code is released under a tri EPL/GPL/LGPL license. You can use it,
# redistribute it and/or modify it under the terms of the:
#
# Eclipse Public License version 1.0
# GNU General Public License version 2
# GNU Lesser General Public License version 2.1
# OTHER DEALINGS IN THE SOFTWARE.

require_relative '../../../../ruby/spec_helper'

describe "Truffle::Array.steal_storage" do
def storage(ary)
Truffle::Debug.array_storage(ary)
end

before :each do
@array = %i[first second third]
end

it "should no-op when called on itself" do
copy = @array.dup

Truffle::Array.steal_storage(@array, @array)

storage(@array).should == "Object[]"
@array.should == copy
end

it "should take ownership of the store" do
other = [1, 2, 3, 4, 5]
other_copy = other.dup

Truffle::Array.steal_storage(@array, other)

storage(@array).should == "int[]"
@array.should == other_copy

storage(other).should == "null"
other.empty?.should == true
end
end
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@
@CoreClass("Truffle::Array")
public class TruffleArrayNodes {

@CoreMethod(names = "take_ownership_of_store", onSingleton = true, required = 2)
@CoreMethod(names = "steal_storage", onSingleton = true, required = 2)
public abstract static class TakeOwnershipOfStoreNode extends CoreMethodArrayArgumentsNode {

@Specialization(guards = "array == other")
16 changes: 8 additions & 8 deletions truffle/src/main/ruby/core/array.rb
Original file line number Diff line number Diff line change
@@ -811,7 +811,7 @@ def flatten!(level=-1)

out = new_reserved size
if recursively_flatten(self, out, level)
Truffle::Array.take_ownership_of_store(self, out)
Truffle::Array.steal_storage(self, out)
return self
end

@@ -987,7 +987,7 @@ def keep_if(&block)

Truffle.check_frozen

Truffle::Array.take_ownership_of_store(self, select(&block))
Truffle::Array.steal_storage(self, select(&block))
end

def last(n=undefined)
@@ -1337,7 +1337,7 @@ def rotate!(cnt=1)
return self if length == 0 || length == 1

ary = rotate(cnt)
Truffle::Array.take_ownership_of_store(self, ary)
Truffle::Array.steal_storage(self, ary)
end

class SampleRandom
@@ -1467,7 +1467,7 @@ def select!(&block)
Truffle.check_frozen

ary = select(&block)
Truffle::Array.take_ownership_of_store(self, ary) unless size == ary.size
Truffle::Array.steal_storage(self, ary) unless size == ary.size
end

def set_index(index, ent, fin=undefined)
@@ -1748,7 +1748,7 @@ def sort_by!(&block)

return to_enum(:sort_by!) { size } unless block_given?

Truffle::Array.take_ownership_of_store(self, sort_by(&block))
Truffle::Array.steal_storage(self, sort_by(&block))
end

# Sorts this Array in-place. See #sort.
@@ -2044,7 +2044,7 @@ def mergesort!
width *= 2
end

Truffle::Array.take_ownership_of_store(self, source)
Truffle::Array.steal_storage(self, source)

self
end
@@ -2108,7 +2108,7 @@ def mergesort_block!(block)
width *= 2
end

Truffle::Array.take_ownership_of_store(self, source)
Truffle::Array.steal_storage(self, source)

self
end
@@ -2399,7 +2399,7 @@ def element_reference_fallback(method_name, args)
def sort!(&block)
Truffle.check_frozen

Truffle::Array.take_ownership_of_store(self, sort(&block))
Truffle::Array.steal_storage(self, sort(&block))
end
public :sort!
end