From 44374034268913246d517ff25365e0bccb453e02 Mon Sep 17 00:00:00 2001 From: marcandre Date: Tue, 6 Nov 2012 17:15:45 +0000 Subject: * string.c: Support for String#{each_byte,each_char,each_codepoint}.size [Feature #6636] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37520 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- string.c | 25 ++++++++++++++++++++++--- test/ruby/test_enumerator.rb | 6 ++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/string.c b/string.c index d674e8903c..224b018374 100644 --- a/string.c +++ b/string.c @@ -6222,6 +6222,11 @@ rb_str_each_line(int argc, VALUE *argv, VALUE str) return orig; } +static VALUE +rb_str_each_byte_size(VALUE str, VALUE args) +{ + return LONG2FIX(RSTRING_LEN(str)); +} /* * call-seq: @@ -6246,13 +6251,27 @@ rb_str_each_byte(VALUE str) { long i; - RETURN_ENUMERATOR(str, 0, 0); + RETURN_SIZED_ENUMERATOR(str, 0, 0, rb_str_each_byte_size); for (i=0; i