summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--array.c48
2 files changed, 18 insertions, 34 deletions
diff --git a/ChangeLog b/ChangeLog
index b656eed..176dddb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Tue Dec 3 14:05:49 2013 Masaki Matsushita <glass.saga@gmail.com>
+
+ * array.c (rb_ary_uniq_bang): remove duplicate code.
+
Tue Dec 3 13:40:42 2013 Masaki Matsushita <glass.saga@gmail.com>
* array.c (ary_add_hash): set and return values because string keys
diff --git a/array.c b/array.c
index 8a71e2c..7417a7c 100644
--- a/array.c
+++ b/array.c
@@ -4063,13 +4063,6 @@ rb_ary_or(VALUE ary1, VALUE ary2)
}
static int
-push_val(st_data_t key, st_data_t val, st_data_t ary)
-{
- rb_ary_push((VALUE)ary, (VALUE)val);
- return ST_CONTINUE;
-}
-
-static int
push_value(st_data_t key, st_data_t val, st_data_t ary)
{
rb_ary_push((VALUE)ary, (VALUE)val);
@@ -4110,36 +4103,23 @@ rb_ary_uniq_bang(VALUE ary)
rb_ary_modify_check(ary);
if (RARRAY_LEN(ary) <= 1)
return Qnil;
- if (rb_block_given_p()) {
+ if (rb_block_given_p())
hash = ary_make_hash_by(ary);
- hash_size = RHASH_SIZE(hash);
- if (RARRAY_LEN(ary) == hash_size) {
- return Qnil;
- }
- rb_ary_modify_check(ary);
- ARY_SET_LEN(ary, 0);
- if (ARY_SHARED_P(ary) && !ARY_EMBED_P(ary)) {
- rb_ary_unshare(ary);
- FL_SET_EMBED(ary);
- }
- ary_resize_capa(ary, hash_size);
- st_foreach(rb_hash_tbl_raw(hash), push_value, ary);
- }
- else {
+ else
hash = ary_make_hash(ary);
- hash_size = RHASH_SIZE(hash);
- if (RARRAY_LEN(ary) == hash_size) {
- return Qnil;
- }
- rb_ary_modify_check(ary);
- ARY_SET_LEN(ary, 0);
- if (ARY_SHARED_P(ary) && !ARY_EMBED_P(ary)) {
- rb_ary_unshare(ary);
- FL_SET_EMBED(ary);
- }
- ary_resize_capa(ary, hash_size);
- st_foreach(rb_hash_tbl_raw(hash), push_val, ary);
+
+ hash_size = RHASH_SIZE(hash);
+ if (RARRAY_LEN(ary) == hash_size) {
+ return Qnil;
+ }
+ rb_ary_modify_check(ary);
+ ARY_SET_LEN(ary, 0);
+ if (ARY_SHARED_P(ary) && !ARY_EMBED_P(ary)) {
+ rb_ary_unshare(ary);
+ FL_SET_EMBED(ary);
}
+ ary_resize_capa(ary, hash_size);
+ st_foreach(rb_hash_tbl_raw(hash), push_value, ary);
ary_recycle_hash(hash);
return ary;