mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* array.c (rb_ary_nitems): add the block feature to Array#nitems.
suggested by Bertram Scharpf <lists@bertram-scharpf.de> in [ruby-talk:134083]. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8593 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
5ef43814a8
commit
8d5e6a0fc6
5 changed files with 28 additions and 24 deletions
|
@ -1,3 +1,9 @@
|
|||
Wed Jun 8 12:25:59 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||
|
||||
* array.c (rb_ary_nitems): add the block feature to Array#nitems.
|
||||
suggested by Bertram Scharpf <lists@bertram-scharpf.de> in
|
||||
[ruby-talk:134083].
|
||||
|
||||
Wed Jun 8 11:11:34 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||
|
||||
* bignum.c (get2comp): revert all prior changes, and calculate
|
||||
|
|
26
array.c
26
array.c
|
@ -2890,11 +2890,16 @@ rb_ary_compact(ary)
|
|||
/*
|
||||
* call-seq:
|
||||
* array.nitems -> int
|
||||
* array.nitems { |item| block } -> int
|
||||
*
|
||||
* Returns the number of non-<code>nil</code> elements in _self_.
|
||||
* If a block is given, the elements yielding a true value are
|
||||
* counted.
|
||||
*
|
||||
* May be zero.
|
||||
*
|
||||
* [ 1, nil, 3, nil, 5 ].nitems #=> 3
|
||||
* [5,6,7,8,9].nitems { |x| x % 2 != 0 } #=> 3
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
|
@ -2902,14 +2907,23 @@ rb_ary_nitems(ary)
|
|||
VALUE ary;
|
||||
{
|
||||
long n = 0;
|
||||
VALUE *p, *pend;
|
||||
|
||||
p = RARRAY(ary)->ptr;
|
||||
pend = p + RARRAY(ary)->len;
|
||||
if (rb_block_given_p()) {
|
||||
long i;
|
||||
|
||||
while (p < pend) {
|
||||
if (!NIL_P(*p)) n++;
|
||||
p++;
|
||||
for (i=0; i<RARRAY(ary)->len; i++) {
|
||||
VALUE v = RARRAY(ary)->ptr[i];
|
||||
if (RTEST(rb_yield(v))) n++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
VALUE *p = RARRAY(ary)->ptr;
|
||||
VALUE *pend = p + RARRAY(ary)->len;
|
||||
|
||||
while (p < pend) {
|
||||
if (!NIL_P(*p)) n++;
|
||||
p++;
|
||||
}
|
||||
}
|
||||
return LONG2NUM(n);
|
||||
}
|
||||
|
|
16
bignum.c
16
bignum.c
|
@ -1065,22 +1065,6 @@ rb_big_neg(x)
|
|||
}
|
||||
RBIGNUM(z)->sign = !RBIGNUM(z)->sign;
|
||||
if (RBIGNUM(x)->sign) get2comp(z, Qtrue);
|
||||
#if 0
|
||||
i = RBIGNUM(x)->len;
|
||||
if (RBIGNUM(x)->sign) {
|
||||
while (i--) {
|
||||
if (ds[i]) nz = Qtrue;
|
||||
}
|
||||
if (!nz) {
|
||||
z = bignew(RBIGNUM(x)->len+1, 1);
|
||||
for (i=0; i<RBIGNUM(x)->len; i++) {
|
||||
BDIGITS(z)[i] = BDIGITS(x)[i];
|
||||
}
|
||||
BDIGITS(z)[i] = 1;
|
||||
BDIGITS(z)[0] = 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return bignorm(z);
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ class TestRipper_ParserEvents < Test::Unit::TestCase
|
|||
|
||||
def test_void_stmt
|
||||
assert_equal '[void()]', parse('')
|
||||
assert_equal '[void()]', parse(';;')
|
||||
assert_equal '[void()]', parse('; ;')
|
||||
end
|
||||
|
||||
def test_var_ref
|
||||
|
|
|
@ -640,7 +640,7 @@ class TestRipper_ScannerEvents < Test::Unit::TestCase
|
|||
assert_equal %w(;),
|
||||
scan('semicolon', ';')
|
||||
assert_equal %w(; ;),
|
||||
scan('semicolon', ';;')
|
||||
scan('semicolon', '; ;')
|
||||
assert_equal %w(; ; ;),
|
||||
scan('semicolon', 'nil;nil;nil;')
|
||||
assert_equal %w(; ; ;),
|
||||
|
|
Loading…
Reference in a new issue