Skip to content

Commit

Permalink
Merge branch 'master' into truffle-head
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvdrum committed Mar 19, 2015
2 parents 8ccb1f1 + ea238d9 commit 46683af
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 80 deletions.
19 changes: 0 additions & 19 deletions spec/truffle/tags/core/array/join_tags.txt
@@ -1,20 +1 @@
fails:Array#join returns a string formed by concatenating each element.to_str separated by separator
fails:Array#join uses the same separator with nested arrays
fails:Array#join attempts coercion via #to_str first
fails:Array#join attempts coercion via #to_ary second
fails:Array#join attempts coercion via #to_s third
fails:Array#join raises a NoMethodError if an element does not respond to #to_str, #to_ary, or #to_s
fails:Array#join taints the result if the Array is tainted and non-empty
fails:Array#join taints the result if the result of coercing an element is tainted
fails:Array#join untrusts the result if the Array is untrusted and non-empty
fails:Array#join untrusts the result if the result of coercing an element is untrusted
fails:Array#join uses the first encoding when other strings are compatible
fails:Array#join fails for arrays with incompatibly-encoded strings
fails:Array#join does not separate elements when the passed separator is nil
fails:Array#join calls #to_str to convert the separator to a String
fails:Array#join does not call #to_str on the separator if the array is empty
fails:Array#join with a tainted separator taints the result if the array has two or more elements
fails:Array#join with an untrusted separator untrusts the result if the array has two or more elements
fails:Array#join with $, separates elements with default separator when the passed separator is nil
fails:Array#join raises an ArgumentError when the Array is recursive
fails:Array#join uses the widest common encoding when other strings are incompatible
2 changes: 1 addition & 1 deletion tool/jt.rb
Expand Up @@ -19,7 +19,7 @@
module Utilities

def self.graal_version
File.foreach("#{JRUBY_DIR}/truffle/pom.rb").each do |line|
File.foreach("#{JRUBY_DIR}/truffle/pom.rb") do |line|
if /jar 'com.oracle:truffle:(\d+\.\d+(?:-SNAPSHOT)?)'/ =~ line
break $1
end
Expand Down
Expand Up @@ -16,13 +16,8 @@
*/
public final class CoreSourceSection extends NullSourceSection {

private final String className;
private final String methodName;

public CoreSourceSection(String className, String methodName) {
super("core", String.format("%s#%s", className, methodName));
this.className = className;
this.methodName = methodName;
}

}
46 changes: 0 additions & 46 deletions truffle/src/main/java/org/jruby/truffle/nodes/core/ArrayNodes.java
Expand Up @@ -1728,52 +1728,6 @@ public Object insert(RubyArray array, int index, int value) {

}

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

public JoinNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

public JoinNode(JoinNode prev) {
super(prev);
}

@Specialization
public RubyString join(RubyArray array, UndefinedPlaceholder unused) {
Object separator = getContext().getCoreLibrary().getGlobalVariablesObject().getInstanceVariable("$,");
if (separator == nil()) {
separator = getContext().makeString("");
}

if (separator instanceof RubyString) {
return join(array, (RubyString) separator);
} else {
throw new UnsupportedOperationException();
}
}

@Specialization
public RubyString join(RubyArray array, RubyString separator) {
notDesignedForCompilation();

final StringBuilder builder = new StringBuilder();

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

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

builder.append(objects[n]);
}

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

}

@CoreMethod(names = {"map", "collect"}, needsBlock = true, returnsEnumeratorIfNoBlock = true)
@ImportStatic(ArrayGuards.class)
public abstract static class MapNode extends YieldingCoreMethodNode {
Expand Down
Expand Up @@ -21,13 +21,13 @@
public abstract class EncodingPrimitiveNodes {

@RubiniusPrimitive(name = "encoding_get_object_encoding", needsSelf = false)
public static abstract class EncodingGetObjectEncodingPrimitiveNode extends RubiniusPrimitiveNode {
public static abstract class EncodingGetObjectEncodingNode extends RubiniusPrimitiveNode {

public EncodingGetObjectEncodingPrimitiveNode(RubyContext context, SourceSection sourceSection) {
public EncodingGetObjectEncodingNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

public EncodingGetObjectEncodingPrimitiveNode(EncodingGetObjectEncodingPrimitiveNode prev) {
public EncodingGetObjectEncodingNode(EncodingGetObjectEncodingNode prev) {
super(prev);
}

Expand Down
Expand Up @@ -55,7 +55,6 @@

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.utilities.ConditionProfile;
import org.jcodings.Encoding;
Expand All @@ -65,8 +64,6 @@
import org.jruby.truffle.nodes.cast.TaintResultNode;
import org.jruby.truffle.nodes.core.StringNodes;
import org.jruby.truffle.nodes.core.StringNodesFactory;
import org.jruby.truffle.nodes.dispatch.CallDispatchHeadNode;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNodeFactory;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.UndefinedPlaceholder;
import org.jruby.truffle.runtime.control.RaiseException;
Expand Down Expand Up @@ -577,13 +574,13 @@ public Object stringIndex(RubyString string, RubyString pattern, int start) {
}

@RubiniusPrimitive(name = "string_character_byte_index", needsSelf = false)
public static abstract class StringCharacterByteIndexPrimitiveNode extends RubiniusPrimitiveNode {
public static abstract class CharacterByteIndexNode extends RubiniusPrimitiveNode {

public StringCharacterByteIndexPrimitiveNode(RubyContext context, SourceSection sourceSection) {
public CharacterByteIndexNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

public StringCharacterByteIndexPrimitiveNode(StringCharacterByteIndexPrimitiveNode prev) {
public CharacterByteIndexNode(CharacterByteIndexNode prev) {
super(prev);
}

Expand Down
46 changes: 46 additions & 0 deletions truffle/src/main/ruby/core/rubinius/common/array.rb
Expand Up @@ -634,6 +634,52 @@ def inspect

alias_method :to_s, :inspect

def join(sep=nil)
return "".force_encoding(Encoding::US_ASCII) if @total == 0

out = ""
raise ArgumentError, "recursive array join" if Thread.detect_recursion self do
sep = sep.nil? ? $, : StringValue(sep)

# We've manually unwound the first loop entry for performance
# reasons.
x = @tuple[@start]

if str = String.try_convert(x)
x = str
elsif ary = Array.try_convert(x)
x = ary.join(sep)
else
x = x.to_s
end

out.force_encoding(x.encoding)
out << x

total = @start + size()
i = @start + 1

while i < total
out << sep if sep

x = @tuple[i]

if str = String.try_convert(x)
x = str
elsif ary = Array.try_convert(x)
x = ary.join(sep)
else
x = x.to_s
end

out << x
i += 1
end
end

Rubinius::Type.infect(out, self)
end

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

Expand Down

0 comments on commit 46683af

Please sign in to comment.