Skip to content
Browse files

Update master to 69434c9

  • Loading branch information...
2 parents 389ec1a + 69434c9 commit a8382a25e0448d0f5127246947a064f5cf394c15 @macrotis committed May 23, 2012
Showing with 32 additions and 7 deletions.
  1. +29 −4 array.c
  2. +3 −3 file.c
View
33 array.c
@@ -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)
@@ -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
@@ -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++) {
View
6 file.c
@@ -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))
@@ -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);
@@ -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]);

0 comments on commit a8382a2

Please sign in to comment.
Something went wrong with that request. Please try again.