[macruby-changes] [1904] MacRuby/branches/experimental/hash.c
source_changes at macosforge.org
source_changes at macosforge.org
Fri Jun 19 22:06:56 PDT 2009
Revision: 1904
http://trac.macosforge.org/projects/ruby/changeset/1904
Author: lsansonetti at apple.com
Date: 2009-06-19 22:06:56 -0700 (Fri, 19 Jun 2009)
Log Message:
-----------
Hash#[]: accelerate the call to #default in case the given key is not found
Modified Paths:
--------------
MacRuby/branches/experimental/hash.c
Modified: MacRuby/branches/experimental/hash.c
===================================================================
--- MacRuby/branches/experimental/hash.c 2009-06-20 04:49:53 UTC (rev 1903)
+++ MacRuby/branches/experimental/hash.c 2009-06-20 05:06:56 UTC (rev 1904)
@@ -37,8 +37,11 @@
VALUE rb_cNSMutableHash;
static VALUE envtbl;
-static ID id_hash, id_yield, id_default;
+static ID id_hash, id_yield;
+static void *defaultCache = NULL;
+static SEL selDefault = 0;
+
VALUE
rb_hash(VALUE obj)
{
@@ -469,9 +472,10 @@
{
VALUE val;
- if (!CFDictionaryGetValueIfPresent((CFDictionaryRef)hash, (const void *)RB2OC(key),
+ if (!CFDictionaryGetValueIfPresent((CFDictionaryRef)hash,
+ (const void *)RB2OC(key),
(const void **)&val)) {
- return rb_funcall(hash, id_default, 1, key);
+ return rb_vm_call_with_cache(defaultCache, hash, selDefault, 0, NULL);
}
val = OC2RB(val);
return val;
@@ -2479,9 +2483,11 @@
void
Init_Hash(void)
{
+ selDefault = sel_registerName("default");
+ defaultCache = rb_vm_get_call_cache(selDefault);
+
id_hash = rb_intern("hash");
id_yield = rb_intern("yield");
- id_default = rb_intern("default");
rb_cCFHash = (VALUE)objc_getClass("NSCFDictionary");
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090619/37248b26/attachment-0001.html>
More information about the macruby-changes
mailing list