Skip to content

Instantly share code, notes, and snippets.

@headius
Created June 2, 2014 07:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save headius/ca4c8f5c4f70c794950a to your computer and use it in GitHub Desktop.
Save headius/ca4c8f5c4f70c794950a to your computer and use it in GitHub Desktop.
Patches to improve Time.parse performance.
diff --git a/core/src/main/java/org/jruby/RubyHash.java b/core/src/main/java/org/jruby/RubyHash.java
index 661d394..9dadce6 100644
--- a/core/src/main/java/org/jruby/RubyHash.java
+++ b/core/src/main/java/org/jruby/RubyHash.java
@@ -1624,7 +1624,13 @@ public class RubyHash extends RubyObject implements Map {
iteratorVisitAll(new Visitor() {
@Override
public void visit(IRubyObject key, IRubyObject value) {
- if (block.yieldArray(context, RubyArray.newArray(runtime, key, value), null, null).isTrue()) {
+ IRubyObject ret;
+ if (block.arity().getValue() == 2) {
+ ret = block.yieldSpecific(context, key, value);
+ } else {
+ ret = block.yieldArray(context, RubyArray.newArray(runtime, key, value), null, null);
+ }
+ if (ret.isTrue()) {
self.delete(context, key, Block.NULL_BLOCK);
}
}
diff --git a/lib/ruby/2.1/date/format.rb b/lib/ruby/2.1/date/format.rb
index 39c9137..30f547c 100644
--- a/lib/ruby/2.1/date/format.rb
+++ b/lib/ruby/2.1/date/format.rb
@@ -120,10 +120,17 @@ class Date
set = t.chomp!('=')
t = t.intern
if set
- @elem[t] = args[0]
+ ret = @elem[t] = args[0]
else
- @elem[t]
+ ret = @elem[t]
end
+
+ self.class.class_eval <<-EOF
+ def #{t}; @elem[:#{t}]; end
+ def #{t}=(x); @elem[:#{t}]=x; end
+ EOF
+
+ ret
end
def to_hash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment