Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Truffle] Adding Array#combination to array.rb #2681

Merged
merged 3 commits into from Mar 11, 2015

Conversation

bjfish
Copy link
Contributor

@bjfish bjfish commented Mar 11, 2015

@bjfish
Copy link
Contributor Author

bjfish commented Mar 11, 2015

I didn't call reallocate(see the comment there) in Array#fill because we don't use Tuple internally. Please review.

@chrisseaton
Copy link
Contributor

What do you mean by 'adapted form tuple.cpp'? I only see Ruby code here? Have you written some from scratch by copying the Rubinius C++ code into Ruby?

@chrisseaton chrisseaton added this to the truffle-dev milestone Mar 11, 2015
@bjfish
Copy link
Contributor Author

bjfish commented Mar 11, 2015

@chrisseaton that is correct, ruby from scratch after looking at the c++ code. I'm not the best at reading c++ code so requested some review on that.

Also, in reverse! Using an in-place reverse instead of the Rubinius.primitive :tuple_reverse from tuple.rb

@bjfish
Copy link
Contributor Author

bjfish commented Mar 11, 2015

@chrisseaton here is the code for Tuple.pattern

  // @todo performance primitive; could be replaced with Ruby
  Tuple* Tuple::pattern(STATE, Fixnum* size, Object* val) {
    native_int cnt = size->to_native();

    if(cnt < 0) {
      Exception::argument_error(state, "negative tuple size");
    }

    Tuple* tuple = Tuple::create_dirty(state, cnt);

    for(native_int i = 0; i < cnt; i++) {
      // bounds checking is covered because we instantiated the tuple
      // in this method
      tuple->field[i] = val;
    }

    // val is referend size times, we only need to hit the write
    // barrier once
    tuple->write_barrier(state, val);
    return tuple;
  }

I thought that just translated to

def self.pattern(size, val)
  Array.new(size, val)
end

@chrisseaton
Copy link
Contributor

It does yeah. I was asking because I was worried about the licensing requirements if code had been copied from Rubinius C++ to Ruby - we'd have to mark that very clearly. But this is trivial code and hasn't really been copied - you've just deferred to an existing method of our implementation.

chrisseaton added a commit that referenced this pull request Mar 11, 2015
[Truffle] Adding Array#combination to array.rb
@chrisseaton chrisseaton merged commit 4192682 into jruby:master Mar 11, 2015
@enebo enebo added this to the Non-Release milestone Dec 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants