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

Commits on Aug 2, 2016

  1. [Truffle] Help partial evaluation of Iterable/Iterator by giving spec…

    …ific types in BoundaryUtils.
    eregon committed Aug 2, 2016
    Copy the full SHA
    b8e96aa View commit details
  2. Copy the full SHA
    1ae3d7d View commit details
  3. Copy the full SHA
    ea9ddbb View commit details
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@
import org.jruby.truffle.Layouts;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.language.RubyGuards;
import org.jruby.truffle.util.BoundaryUtils.BoundaryIterable;
import org.jruby.truffle.util.StringUtils;
import java.util.Collections;
import java.util.Iterator;
@@ -117,17 +118,17 @@ public static Iterator<KeyValue> iterateKeyValues(DynamicObject hash) {
}

@TruffleBoundary
public static Iterable<KeyValue> iterableKeyValues(final DynamicObject hash) {
public static BoundaryIterable<KeyValue> iterableKeyValues(final DynamicObject hash) {
assert RubyGuards.isRubyHash(hash);

return new Iterable<KeyValue>() {
return BoundaryIterable.wrap(new Iterable<KeyValue>() {

@Override
public Iterator<KeyValue> iterator() {
return iterateKeyValues(hash);
}

};
});
}

}
Original file line number Diff line number Diff line change
@@ -92,6 +92,8 @@
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

@CoreClass("Psych::Parser")
public abstract class PsychParserNodes {
@@ -184,8 +186,8 @@ public Object parse(
Map<String, String> tagsMap = startEvent.getTags();
DynamicObject tags = Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), null, 0);

if (tagsMap != null && tagsMap.size() > 0) {
for (Map.Entry<String, String> tag : BoundaryIterable.wrap(tagsMap.entrySet())) {
if (tagsMap != null && size(tagsMap) > 0) {
for (Map.Entry<String, String> tag : BoundaryIterable.wrap(entrySet(tagsMap))) {
Object key = stringFor(getKey(tag), tainted, taintNode);
Object value = stringFor(getValue(tag), tainted, taintNode);
tagPushNode.execute(frame,
@@ -328,6 +330,16 @@ private DynamicObject createUTF8String(String value) {
return createString(StringOperations.encodeRope(value, UTF8Encoding.INSTANCE));
}

@TruffleBoundary
private int size(Map<String, String> tagsMap) {
return tagsMap.size();
}

@TruffleBoundary
private Set<Entry<String, String>> entrySet(Map<String, String> tagsMap) {
return tagsMap.entrySet();
}

@TruffleBoundary
private String getKey(Map.Entry<String, String> tag) {
return tag.getKey();
16 changes: 11 additions & 5 deletions truffle/src/main/java/org/jruby/truffle/util/BoundaryUtils.java
Original file line number Diff line number Diff line change
@@ -14,9 +14,9 @@

public class BoundaryUtils {

public static class BoundaryIterable<E> implements Iterable<E> {
public static final class BoundaryIterable<E> implements Iterable<E> {

public static <E> Iterable<E> wrap(Iterable<E> iterable) {
public static <E> BoundaryIterable<E> wrap(Iterable<E> iterable) {
return new BoundaryIterable<>(iterable);
}

@@ -27,12 +27,18 @@ public BoundaryIterable(Iterable<E> iterable) {
}

@Override
public Iterator<E> iterator() {
return new BoundaryIterator<E>(iterable.iterator());
public BoundaryIterator<E> iterator() {
return new BoundaryIterator<E>(getIterator());
}

@TruffleBoundary
private Iterator<E> getIterator() {
return iterable.iterator();
}

}

public static class BoundaryIterator<E> implements Iterator<E> {
public static final class BoundaryIterator<E> implements Iterator<E> {

private final Iterator<E> iterator;