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

Commits on Mar 7, 2015

  1. [Truffle] Hash#assoc

    chrisseaton committed Mar 7, 2015
    Copy the full SHA
    c424f18 View commit details
  2. [Truffle] Hash#rassoc

    chrisseaton committed Mar 7, 2015
    Copy the full SHA
    f049689 View commit details
  3. [Truffle] Hash#rehash

    chrisseaton committed Mar 7, 2015
    Copy the full SHA
    6c31cfc View commit details
  4. [Truffle] Hash#sort

    chrisseaton committed Mar 7, 2015
    Copy the full SHA
    ac8b299 View commit details
  5. [Truffle] Hash#values_at

    chrisseaton committed Mar 7, 2015
    Copy the full SHA
    03442e4 View commit details
8 changes: 0 additions & 8 deletions spec/truffle/tags/core/hash/assoc_tags.txt

This file was deleted.

8 changes: 0 additions & 8 deletions spec/truffle/tags/core/hash/rassoc_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/hash/rehash_tags.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
fails:Hash#rehash reorganizes the hash by recomputing all key hash codes
fails:Hash#rehash raises a RuntimeError if called on a frozen instance
1 change: 0 additions & 1 deletion spec/truffle/tags/core/hash/sort_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/hash/values_at_tags.txt

This file was deleted.

33 changes: 33 additions & 0 deletions truffle/src/main/java/org/jruby/truffle/nodes/core/HashNodes.java
Original file line number Diff line number Diff line change
@@ -1160,6 +1160,39 @@ public int sizePackedArray(RubyHash hash) {

}

@CoreMethod(names = "rehash", raiseIfFrozenSelf = true)
public abstract static class RehashNode extends HashCoreMethodNode {

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

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

@Specialization(guards = "isNull")
public RubyHash rehashNull(RubyHash hash) {
return hash;
}

@Specialization(guards = {"!isNull", "!isBuckets"})
public RubyHash rehashPackedArray(RubyHash hash) {
// Nothing to do as we weren't using the hash code anyway
return hash;
}

@Specialization(guards = "isBuckets")
public RubyHash rehashBuckets(RubyHash hash) {
notDesignedForCompilation();

HashOperations.verySlowSetKeyValues(hash, HashOperations.verySlowToKeyValues(hash), hash.isCompareByIdentity());

return hash;
}

}

@CoreMethod(names = "replace", required = 1)
public abstract static class ReplaceNode extends HashCoreMethodNode {

Original file line number Diff line number Diff line change
@@ -11,10 +11,7 @@

import org.joni.Matcher;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyClass;
import org.jruby.truffle.runtime.core.RubyMatchData;
import org.jruby.truffle.runtime.core.RubyRegexp;
import org.jruby.truffle.runtime.core.RubyString;
import org.jruby.truffle.runtime.core.*;

import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.source.SourceSection;
@@ -91,4 +88,24 @@ public Object setLastMatch(RubyClass regexpClass, Object matchData) {
}

}

@RubiniusPrimitive(name = "regexp_set_block_last_match")
public static abstract class RegexpSetBlockLastMatchPrimitiveNode extends RubiniusPrimitiveNode {

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

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

@Specialization
public RubyNilClass setBlockLastMatch(RubyClass regexpClass) {
// TODO CS 7-Mar-15 what does this do?
return getContext().getCoreLibrary().getNilObject();
}

}

}
11 changes: 11 additions & 0 deletions truffle/src/main/ruby/core/hash.rb
Original file line number Diff line number Diff line change
@@ -31,10 +31,21 @@ def each_item
each do |key, value|
yield KeyValue.new(key, value)
end
nil
end

def merge_fallback(other, &block)
merge(Rubinius::Type.coerce_to other, Hash, :to_hash, &block)
end

def find_item(key)
value = self[key]
if value.nil?
nil
else
# TODO CS 7-Mar-15 maybe we should return the stored key?
KeyValue.new(key, value)
end
end

end
5 changes: 5 additions & 0 deletions truffle/src/main/ruby/core/rubinius/bootstrap/regexp.rb
Original file line number Diff line number Diff line change
@@ -61,4 +61,9 @@ def self.last_match=(match)
raise PrimitiveFailure, "Regexp#set_last_match primitive failed"
end

def self.set_block_last_match
Rubinius.primitive :regexp_set_block_last_match
raise PrimitiveFailure, "Regexp#set_block_last_match primitive failed"
end

end
25 changes: 25 additions & 0 deletions truffle/src/main/ruby/core/rubinius/common/hash.rb
Original file line number Diff line number Diff line change
@@ -205,4 +205,29 @@ def empty?
@size == 0
end

def assoc(key)
each_item { |e| return e.key, e.value if key == e.key }
end

def rassoc(value)
each_item { |e| return e.key, e.value if value == e.value }
end

def sort(&block)
to_a.sort(&block)
end

def values_at(*args)
args.map do |key|
if item = find_item(key)
item.value
else
default key
end
end
end

alias_method :indices, :values_at
alias_method :indexes, :values_at

end