summaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
authorMichael Leibowitz <michael.leibowitz@intel.com>2013-08-15 15:02:54 -0700
committerMichael Leibowitz <michael.leibowitz@intel.com>2013-08-15 15:02:54 -0700
commit6b0e2a11aeccf2ebc707c22548a0c15c8c2bae06 (patch)
treed9d59f4b502927634d32832e963db76629ff5a2e /hash.c
parent3b35de2a90e26b99e2a6d4f61dc56d6ce7ded748 (diff)
downloadruby-6b0e2a11aeccf2ebc707c22548a0c15c8c2bae06.tar.gz
ruby-6b0e2a11aeccf2ebc707c22548a0c15c8c2bae06.tar.bz2
ruby-6b0e2a11aeccf2ebc707c22548a0c15c8c2bae06.zip
Imported Upstream version 1.9.3.p448upstream/1.9.3.p448upstream
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c30
1 files changed, 11 insertions, 19 deletions
diff --git a/hash.c b/hash.c
index 64c5d94..1f2356a 100644
--- a/hash.c
+++ b/hash.c
@@ -2,7 +2,7 @@
hash.c -
- $Author: nobu $
+ $Author: usa $
created at: Mon Nov 22 18:51:18 JST 1993
Copyright (C) 1993-2007 Yukihiro Matsumoto
@@ -824,18 +824,6 @@ struct shift_var {
};
static int
-shift_i(VALUE key, VALUE value, VALUE arg)
-{
- struct shift_var *var = (struct shift_var *)arg;
-
- if (key == Qundef) return ST_CONTINUE;
- if (var->key != Qundef) return ST_STOP;
- var->key = key;
- var->val = value;
- return ST_DELETE;
-}
-
-static int
shift_i_safe(VALUE key, VALUE value, VALUE arg)
{
struct shift_var *var = (struct shift_var *)arg;
@@ -866,16 +854,20 @@ rb_hash_shift(VALUE hash)
rb_hash_modify(hash);
var.key = Qundef;
- rb_hash_foreach(hash, RHASH(hash)->iter_lev > 0 ? shift_i_safe : shift_i,
- (VALUE)&var);
+ if (RHASH(hash)->iter_lev == 0) {
+ if (st_shift(RHASH(hash)->ntbl, &var.key, &var.val)) {
+ return rb_assoc_new(var.key, var.val);
+ }
+ }
+ else {
+ rb_hash_foreach(hash, shift_i_safe, (VALUE)&var);
- if (var.key != Qundef) {
- if (RHASH(hash)->iter_lev > 0) {
+ if (var.key != Qundef) {
rb_hash_delete_key(hash, var.key);
+ return rb_assoc_new(var.key, var.val);
}
- return rb_assoc_new(var.key, var.val);
}
- else if (FL_TEST(hash, HASH_PROC_DEFAULT)) {
+ if (FL_TEST(hash, HASH_PROC_DEFAULT)) {
return rb_funcall(RHASH_IFNONE(hash), id_yield, 2, hash, Qnil);
}
else {