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] Moving Array#to_s to array.rb #2711

Merged
merged 1 commit into from Mar 17, 2015

Conversation

bjfish
Copy link
Contributor

@bjfish bjfish commented Mar 16, 2015

No description provided.

end

Rubinius::Type.infect(result, self)
#result.shorten!(2) # MODIFIED We don't implement string shorten.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you make this change? We'd much prefer shimming shorten! to do nothing rather than have this line commented out.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chrisseaton Yes, I made this change. I'm adding MODIFIED in the comments if I change things.

It looks like String#shorten! is only used in 2 places: io and here. So, I'm a little hesitant to add it to the string public methods.

Alternatively, I could leave this as byteslice or rewrite this method a little. I think the concatenating part of this method is a little ugly. I would write it something like this:

  def inspect
    return "[]".force_encoding(Encoding::US_ASCII) if @total == 0
    elements = Array.new(self.size + 2)    
    elements[0] = "["
    elements[self.size - 1] = "]"

    first_encoding = nil
    return "[...]" if Thread.detect_recursion self do
      each_with_index do |element, index|
        temp = element.inspect
        first_encoding = temp.encoding if index == 0
        elements[i] = temp
      end
    end

    result = elements.join(", ").force_encoding(first_encoding)
    Rubinius::Type.infect(result, self)
    result
  end

I'll do whatever you prefer: adding shorten!, leave as is, or rewriting.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'd rather you left inspect as exactly in the Rubinius code, and then implement an empty shorten! as a shim - like this https://github.com/jruby/jruby/blob/master/truffle/src/main/ruby/core/shims.rb#L59-L60.

It's possible that this will cause problems later when we shimmed methods that silently do nothing, but at least they're easy to search for and understand. It's worked well for us so far.

@bjfish
Copy link
Contributor Author

bjfish commented Mar 17, 2015

@chrisseaton fixed to use String#shorten!

@chrisseaton chrisseaton added this to the truffle-dev milestone Mar 17, 2015
chrisseaton added a commit that referenced this pull request Mar 17, 2015
[Truffle] Moving Array#to_s to array.rb
@chrisseaton chrisseaton merged commit 02a4da2 into jruby:master Mar 17, 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

3 participants