* hash.c (rb_hash_update_by): new API for Hash#update.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30078 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
5c6b43d91e
commit
2d4b0d6261
@ -1,3 +1,7 @@
|
|||||||
|
Sat Dec 4 11:21:50 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* hash.c (rb_hash_update_by): new API for Hash#update.
|
||||||
|
|
||||||
Sat Dec 4 11:18:10 2010 Tanaka Akira <akr@fsij.org>
|
Sat Dec 4 11:18:10 2010 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
* class.c: parenthesize macro arguments.
|
* class.c: parenthesize macro arguments.
|
||||||
|
37
hash.c
37
hash.c
@ -1785,6 +1785,43 @@ rb_hash_update(VALUE hash1, VALUE hash2)
|
|||||||
return hash1;
|
return hash1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct update_arg {
|
||||||
|
VALUE hash;
|
||||||
|
rb_hash_update_func *func;
|
||||||
|
};
|
||||||
|
|
||||||
|
static int
|
||||||
|
rb_hash_update_func_i(VALUE key, VALUE value, VALUE arg0)
|
||||||
|
{
|
||||||
|
struct update_arg *arg = (struct update_arg *)arg0;
|
||||||
|
VALUE hash = arg->hash;
|
||||||
|
|
||||||
|
if (key == Qundef) return ST_CONTINUE;
|
||||||
|
if (rb_hash_has_key(hash, key)) {
|
||||||
|
value = (*arg->func)(key, rb_hash_aref(hash, key), value);
|
||||||
|
}
|
||||||
|
hash_update(hash, key);
|
||||||
|
st_insert(RHASH(hash)->ntbl, key, value);
|
||||||
|
return ST_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
VALUE
|
||||||
|
rb_hash_update_by(VALUE hash1, VALUE hash2, rb_hash_update_func *func)
|
||||||
|
{
|
||||||
|
rb_hash_modify(hash1);
|
||||||
|
hash2 = to_hash(hash2);
|
||||||
|
if (func) {
|
||||||
|
struct update_arg arg;
|
||||||
|
arg.hash = hash1;
|
||||||
|
arg.func = func;
|
||||||
|
rb_hash_foreach(hash2, rb_hash_update_func_i, (VALUE)&arg);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
rb_hash_foreach(hash2, rb_hash_update_i, hash1);
|
||||||
|
}
|
||||||
|
return hash1;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* call-seq:
|
||||||
* hsh.merge(other_hash) -> new_hash
|
* hsh.merge(other_hash) -> new_hash
|
||||||
|
@ -436,6 +436,8 @@ VALUE rb_hash_fetch(VALUE, VALUE);
|
|||||||
VALUE rb_hash_aset(VALUE, VALUE, VALUE);
|
VALUE rb_hash_aset(VALUE, VALUE, VALUE);
|
||||||
VALUE rb_hash_delete_if(VALUE);
|
VALUE rb_hash_delete_if(VALUE);
|
||||||
VALUE rb_hash_delete(VALUE,VALUE);
|
VALUE rb_hash_delete(VALUE,VALUE);
|
||||||
|
typedef VALUE rb_hash_update_func(VALUE newkey, VALUE oldkey, VALUE value);
|
||||||
|
VALUE rb_hash_update_by(VALUE hash1, VALUE hash2, rb_hash_update_func *func);
|
||||||
struct st_table *rb_hash_tbl(VALUE);
|
struct st_table *rb_hash_tbl(VALUE);
|
||||||
int rb_path_check(const char*);
|
int rb_path_check(const char*);
|
||||||
int rb_env_path_tainted(void);
|
int rb_env_path_tainted(void);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user