Project

General

Profile

Actions

Bug #3855

closed

String#rindex extremely slow on long UTF8 strings

Added by mike (Michael Selig) over 14 years ago. Updated over 13 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 1.9.3dev (2010-09-21 trunk 29308) [i686-linux]
Backport:
[ruby-core:32498]

Description

=begin
Not really a bug .....
I think this issue was raised a few months ago, but I have done a very simple patch to string.c to fix the problem.

Example:

ruby -e 'p String.new("XXX\u0639" + "X" * 100000).rindex("\u0639")'

takes approx 2.7 secs on my old AMD Athlon system, but only approx 0.02 sec with the patch below. The problem is worst when the search string is either not found or is near the beginning of the string.

The issue is the call to "str_nth()" which has to scan the string repeatedly on multibyte encodings just to locate where to start comparing.

I hope that you will consider applying the patch.

Mike
=end


Files

rindex.pat (553 Bytes) rindex.pat Patch to string.c to speed up String#rindex mike (Michael Selig), 09/22/2010 03:34 PM
Actions #1

Updated by naruse (Yui NARUSE) about 14 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

=begin
This issue was solved with changeset r29331.
Michael, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.

=end

Actions

Also available in: Atom PDF

Like0
Like0