Skip to content

Commit

Permalink
Update master to 69434c9
Browse files Browse the repository at this point in the history
  • Loading branch information
macrotis committed May 23, 2012
2 parents 389ec1a + 69434c9 commit a8382a2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
33 changes: 29 additions & 4 deletions array.c
Expand Up @@ -2699,6 +2699,19 @@ ary_make_hash(VALUE ary1, VALUE ary2)
return hash;
}

static VALUE
ary_make_hash_by(VALUE ary)
{
VALUE hash = rb_hash_new();
for (long i = 0; i < RARRAY_LEN(ary); ++i) {
VALUE v = rb_ary_elt(ary, i), k = rb_yield(v);
if (rb_hash_lookup(hash, k) == Qnil) {
rb_hash_aset(hash, k, v);
}
}
return hash;
}

// Defined on NSArray.
VALUE
rary_diff(VALUE ary1, SEL sel, VALUE ary2)
Expand Down Expand Up @@ -2783,6 +2796,13 @@ rary_or(VALUE ary1, SEL sel, VALUE ary2)
return ary3;
}

static int
push_value(st_data_t key, st_data_t val, st_data_t ary)
{
rb_ary_push((VALUE)ary, (VALUE)val);
return ST_CONTINUE;
}

/*
* call-seq:
* array.uniq! -> array or nil
Expand All @@ -2808,12 +2828,17 @@ rary_uniq_bang(VALUE ary, SEL sel)
return Qnil;
}
if (rb_block_given_p()) {
// TODO
return Qnil;
hash = ary_make_hash_by(ary);
if (RARRAY_LEN(ary) == RHASH_SIZE(hash)) {
return Qnil;
}
RARY(ary)->len = 0;
st_foreach(RHASH_TBL(hash), push_value, ary);
rary_resize(ary, RHASH_SIZE(hash));
}
else {
hash = ary_make_hash(rb_ary_new(), ary);
if (RARRAY_LEN(ary) == (long)RHASH_SIZE(hash)) {
hash = ary_make_hash(ary, 0);
if (RARRAY_LEN(ary) == RHASH_SIZE(hash)) {
return Qnil;
}
for (i=j=0; i<RARRAY_LEN(ary); i++) {
Expand Down
6 changes: 3 additions & 3 deletions file.c
Expand Up @@ -2757,7 +2757,7 @@ rb_file_s_basename(VALUE rcv, SEL sel, int argc, VALUE *argv)
}
FilePathStringValue(fname);
if (RSTRING_LEN(fname) == 0 || !*(name = RSTRING_PTR(fname))) {
return fname;
return rb_str_new3(fname);
}
name = skipprefix(name);
while (isdirsep(*name))
Expand All @@ -2777,7 +2777,7 @@ rb_file_s_basename(VALUE rcv, SEL sel, int argc, VALUE *argv)
if (NIL_P(fext) || !(f = rmext(p, n, StringValueCStr(fext)))) {
f = n;
}
if (f == RSTRING_LEN(fname)) return fname;
if (f == RSTRING_LEN(fname)) return rb_str_new3(fname);
}

basename = rb_str_new(p, f);
Expand Down Expand Up @@ -3330,7 +3330,7 @@ rb_f_test(VALUE rcv, SEL sel, int argc, VALUE *argv)
return rb_file_writable_p(0, 0, argv[1]);

case 'W':
return rb_file_world_writable_p(0, 0, argv[1]);
return rb_file_writable_real_p(0, 0, argv[1]);

case 'x':
return rb_file_executable_p(0, 0, argv[1]);
Expand Down

0 comments on commit a8382a2

Please sign in to comment.