From: Heesob Park Date: 2011-01-22T22:11:09+09:00 Subject: [ruby-core:34787] [Ruby 1.9-Bug#4298] Duration of calling String#[] with the same index is strangely related to string length. Issue #4298 has been updated by Heesob Park. This bug(or feature) is due to the repetitive calling of str_strlen() function. Here is a sentry patch for rb_str_substr() function of string.c --- string.c 2011-01-22 21:25:38.000000000 +0900 +++ string.c.new 2011-01-22 21:28:05.000000000 +0900 @@ -1603,7 +1603,7 @@ if (beg < 0) return Qnil; } } - else if (beg > 0 && beg > str_strlen(str, enc)) { + else if (beg > 0 && beg > RSTRING_LEN(str) && beg > str_strlen(str, enc)) { return Qnil; } if (len == 0) { Before patch: phasis:~ phasis$ /usr/local/bin/ruby t1.rb 0.000000 0.000000 0.000000 ( 0.000398) 1.690000 0.010000 1.700000 ( 1.731168) After patch: phasis:~ phasis$ /usr/local/bin/ruby t1.rb 0.000000 0.000000 0.000000 ( 0.000355) 0.000000 0.000000 0.000000 ( 0.000356) ---------------------------------------- http://redmine.ruby-lang.org/issues/show/4298 ---------------------------------------- http://redmine.ruby-lang.org