On Jun 23, 2009, at 6:03 AM, David R. MacIver (JIRA) wrote:
> Very long runtime (apparently exponential in string size) with
> certain regexps and gsub!
> ----------------------------------------------------------------------------------------
>
> Key: JRUBY-3771
> URL:
http://jira.codehaus.org/browse/JRUBY-3771> Project: JRuby
> Issue Type: Bug
> Affects Versions: JRuby 1.3.1
> Environment: java version "1.6.0_0"
> OpenJDK Runtime Environment (IcedTea6 1.4.1) (6b14-1.4.1-0ubuntu7)
> OpenJDK Server VM (build 14.0-b08, mixed mode
> Reporter: David R. MacIver
> Assignee: Thomas E Enebo
>
>
> The following code appears to take forever to run:
>
> {{{
> cleaner = /((?-mix:(\"|\(|\)|;|-|\:|-|\*|,))| |(?-mix:(!|\?|\.)+))+$/
> string = "................................................... .
> Dear friends! . ."
> string.gsub!(cleaner, "")
> puts string
> }}}
>
> The exact runtime appears to be a function of the number of leading .s
>
> This appears to also be the case in cruby 1.9, so this is presumably
> an inherited bug.
>
> --
> This message is automatically generated by JIRA.
> -
> If you think it was sent incorrectly contact one of the
> administrators:
http://jira.codehaus.org/secure/Administrators.jspa> -
> For more information on JIRA, see:
http://www.atlassian.com/software/jira>
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>
http://xircles.codehaus.org/manage_email>
>
That's because your regular expression is quite flawed.
Dropping the first of the two +s seems to speed it up quite a bit. (I
can't tell if it fits your requirements, but if it does, it's worth
considering.)
Anyway, I don't think it's a bug.
cleaner = /((?-mix:(\"|\(|\)|;|-|\:|-|\*|,))| |(?-mix:(!|\?|\.)))+$/
string = "................................................... . Dear
friends! . .."
string.gsub!(cleaner, "")
puts string
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email