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

Commits on Mar 17, 2015

  1. Copy the full SHA
    98d38ce View commit details
  2. Merge pull request #2711 from bjfish/truffle_array_to_s

    [Truffle] Moving Array#to_s to array.rb
    chrisseaton committed Mar 17, 2015
    Copy the full SHA
    02a4da2 View commit details
6 changes: 0 additions & 6 deletions spec/truffle/tags/core/array/inspect_tags.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
fails:Array#inspect represents a recursive element with '[...]'
fails:Array#inspect taints the result if the Array is non-empty and tainted
fails:Array#inspect taints the result if an element is tainted
fails:Array#inspect untrusts the result if the Array is untrusted
fails:Array#inspect untrusts the result if an element is untrusted
fails:Array#inspect with encoding raises if inspected result is not default external encoding
fails:Array#inspect with encoding use the default external encoding if it is ascii compatible
6 changes: 0 additions & 6 deletions spec/truffle/tags/core/array/to_s_tags.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
fails:Array#to_s represents a recursive element with '[...]'
fails:Array#to_s taints the result if the Array is non-empty and tainted
fails:Array#to_s taints the result if an element is tainted
fails:Array#to_s untrusts the result if the Array is untrusted
fails:Array#to_s untrusts the result if an element is untrusted
fails:Array#to_s with encoding raises if inspected result is not default external encoding
fails:Array#to_s with encoding use the default external encoding if it is ascii compatible
42 changes: 0 additions & 42 deletions truffle/src/main/java/org/jruby/truffle/nodes/core/ArrayNodes.java
Original file line number Diff line number Diff line change
@@ -1672,48 +1672,6 @@ public Object insert(RubyArray array, int index, int value) {

}

@CoreMethod(names = {"inspect", "to_s"})
public abstract static class InspectNode extends CoreMethodNode {

@Child private CallDispatchHeadNode inspect;

public InspectNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
inspect = DispatchHeadNodeFactory.createMethodCall(context);
}

public InspectNode(InspectNode prev) {
super(prev);
inspect = prev.inspect;
}

@Specialization
public RubyString inspect(VirtualFrame frame, RubyArray array) {
notDesignedForCompilation();

final StringBuilder builder = new StringBuilder();
final Object[] objects = array.slowToArray();

builder.append("[");

for (int n = 0; n < objects.length; n++) {
if (n > 0) {
builder.append(", ");
}

// TODO(CS): cast

final RubyString string = (RubyString) inspect.call(frame, objects[n], "inspect", null);
builder.append(string.getBytes().toString());
}

builder.append("]");

return getContext().makeString(builder.toString());
}

}

@CoreMethod(names = "join", optional = 1)
public abstract static class JoinNode extends ArrayCoreMethodNode {

22 changes: 22 additions & 0 deletions truffle/src/main/ruby/core/rubinius/common/array.rb
Original file line number Diff line number Diff line change
@@ -612,6 +612,28 @@ def flatten!(level=-1)
nil
end


def inspect
return "[]".force_encoding(Encoding::US_ASCII) if @total == 0
comma = ", "
result = "["

return "[...]" if Thread.detect_recursion self do
each_with_index do |element, index|
temp = element.inspect
result.force_encoding(temp.encoding) if index == 0
result << temp << comma
end
end

Rubinius::Type.infect(result, self)
result.shorten!(2)
result << "]"
result
end

alias_method :to_s, :inspect

def keep_if(&block)
return to_enum :keep_if unless block_given?

7 changes: 7 additions & 0 deletions truffle/src/main/ruby/core/shims.rb
Original file line number Diff line number Diff line change
@@ -104,6 +104,13 @@ class String
def append(other)
self << other
end

def shorten!(size)
self.modify!
return if @num_bytes == 0
self.num_bytes -= size
end

end

module Kernel