summaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-07-10 10:39:39 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-07-10 10:39:39 +0000
commit302c311199c80ac9094dfa2b9781e6240f6a3092 (patch)
treea9036b0f7aa362e05dc1603d7c1598bf44dc309a /hash.c
parentbc1e2ab306ada94a7169d5812dd8252743553102 (diff)
* hash.c (rb_hash_lookup): added. this function is similar to
rb_hash_aref(), but doesn't call Hash#default when no entry exists. * include/ruby/intern.h: ditto. * insnhelper.ci (lfp_svar_get): use rb_hash_lookup(). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12734 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/hash.c b/hash.c
index b2008350c2..194e4e538a 100644
--- a/hash.c
+++ b/hash.c
@@ -401,6 +401,17 @@ rb_hash_aref(VALUE hash, VALUE key)
return val;
}
+VALUE
+rb_hash_lookup(VALUE hash, VALUE key)
+{
+ VALUE val;
+
+ if (!st_lookup(RHASH(hash)->tbl, key, &val)) {
+ return Qnil; /* without Hash#default */
+ }
+ return val;
+}
+
/*
* call-seq:
* hsh.fetch(key [, default] ) => obj