[前][次][番号順一覧][スレッド一覧]

ruby-changes:3385

From: ko1@a...
Date: 4 Jan 2008 10:24:28 +0900
Subject: [ruby-changes:3385] matz - Ruby:r14878 (trunk): * re.c (rb_reg_search): avoid inner loop for reverse search.

matz	2008-01-04 10:24:12 +0900 (Fri, 04 Jan 2008)

  New Revision: 14878

  Modified files:
    trunk/ChangeLog
    trunk/re.c
    trunk/regexec.c

  Log:
    * re.c (rb_reg_search): avoid inner loop for reverse search.
    
    * regexec.c: unset USE_MATCH_RANGE_MUST_BE_INSIDE_OF_SPECIFIED_RANGE
      which is turned on since oniguruma 5.9.1.

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/regexec.c?r1=14878&r2=14877&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=14878&r2=14877&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/re.c?r1=14878&r2=14877&diff_format=u

Index: re.c
===================================================================
--- re.c	(revision 14877)
+++ re.c	(revision 14878)
@@ -1035,7 +1035,7 @@
     int result;
     VALUE match;
     static struct re_registers regs;
-    int range;
+    char *range = RSTRING_PTR(str);
     rb_encoding *enc = rb_enc_get(str);
 
     if (pos > RSTRING_LEN(str) || pos < 0) {
@@ -1045,33 +1045,15 @@
 
     rb_reg_prepare_re(re, str);
 
-    if (reverse) {
-        char *p = RSTRING_PTR(str) + pos;
-        while (1) {
-            result = onig_match(RREGEXP(re)->ptr,
-                                (UChar*)(RSTRING_PTR(str)),
-                                ((UChar*)(RSTRING_PTR(str)) + RSTRING_LEN(str)),
-                                (UChar*)p,
-                                &regs,
-                                ONIG_OPTION_NONE);
-            if (result != ONIG_MISMATCH) {
-                result = p - RSTRING_PTR(str);
-                break;
-            }
-            if (RSTRING_PTR(str) == p)
-                break;
-            p = rb_enc_prev_char(RSTRING_PTR(str), p, enc);
-        }
+    if (!reverse) {
+	range += RSTRING_LEN(str);
     }
-    else {
-	range = RSTRING_LEN(str) - pos;
-        result = onig_search(RREGEXP(re)->ptr,
-                             (UChar*)(RSTRING_PTR(str)),
-                             ((UChar*)(RSTRING_PTR(str)) + RSTRING_LEN(str)),
-                             ((UChar*)(RSTRING_PTR(str)) + pos),
-                             ((UChar*)(RSTRING_PTR(str)) + pos + range),
-                             &regs, ONIG_OPTION_NONE);
-    }
+    result = onig_search(RREGEXP(re)->ptr,
+			 (UChar*)(RSTRING_PTR(str)),
+			 ((UChar*)(RSTRING_PTR(str)) + RSTRING_LEN(str)),
+			 ((UChar*)(RSTRING_PTR(str)) + pos),
+			 ((UChar*)range),
+			 &regs, ONIG_OPTION_NONE);
 
     if (result < 0) {
 	if (result == ONIG_MISMATCH) {
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 14877)
+++ ChangeLog	(revision 14878)
@@ -1,3 +1,10 @@
+Fri Jan  4 10:22:25 2008  Yukihiro Matsumoto  <matz@r...>
+
+	* re.c (rb_reg_search): avoid inner loop for reverse search.
+
+	* regexec.c: unset USE_MATCH_RANGE_MUST_BE_INSIDE_OF_SPECIFIED_RANGE
+	  which is turned on since oniguruma 5.9.1.
+
 Fri Jan  4 02:53:31 2008  Tanaka Akira  <akr@f...>
 
 	* enc/euc_jp.c: remove eucjp_ prefix.  breakpoint can be specified as
Index: regexec.c
===================================================================
--- regexec.c	(revision 14877)
+++ regexec.c	(revision 14878)
@@ -29,7 +29,7 @@
 
 #include "regint.h"
 
-#define USE_MATCH_RANGE_MUST_BE_INSIDE_OF_SPECIFIED_RANGE
+/* #define USE_MATCH_RANGE_MUST_BE_INSIDE_OF_SPECIFIED_RANGE */
 
 #ifdef USE_CRNL_AS_LINE_TERMINATOR
 #define ONIGENC_IS_MBC_CRNL(enc,p,end) \

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml

[前][次][番号順一覧][スレッド一覧]