summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--hash.c12
-rw-r--r--intern.h1
3 files changed, 19 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index b1b82a924c..335abea7bd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Sat Apr 19 18:42:04 2008 Akinori MUSHA <[email protected]>
+
+ * intern.h, hash.c (rb_hash_lookup): New internal function to
+ check if a key exists in a hash, ignoring #default; backported
+ from 1.9.
+
Fri Apr 18 18:56:57 2008 Akinori MUSHA <[email protected]>
* ext/syck/rubyext.c (syck_genericresolver_node_import): should
diff --git a/hash.c b/hash.c
index 863c98924b..f7ad09032b 100644
--- a/hash.c
+++ b/hash.c
@@ -454,6 +454,18 @@ rb_hash_aref(hash, key)
return val;
}
+VALUE
+rb_hash_lookup(hash, key)
+ VALUE hash, 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
diff --git a/intern.h b/intern.h
index 37c6231f57..aa07ba9e0a 100644
--- a/intern.h
+++ b/intern.h
@@ -270,6 +270,7 @@ VALUE rb_hash _((VALUE));
VALUE rb_hash_new _((void));
VALUE rb_hash_freeze _((VALUE));
VALUE rb_hash_aref _((VALUE, VALUE));
+VALUE rb_hash_lookup _((VALUE, VALUE));
VALUE rb_hash_aset _((VALUE, VALUE, VALUE));
VALUE rb_hash_delete_if _((VALUE));
VALUE rb_hash_delete _((VALUE,VALUE));