From xemacs-m  Sun Mar  2 16:04:12 1997
Received: from mailbox1.ucsd.edu (mailbox1.ucsd.edu [132.239.1.53])
	by xemacs.org (8.8.5/8.8.5) with ESMTP id QAA25269
	for <xemacs-beta@xemacs.org>; Sun, 2 Mar 1997 16:04:06 -0600 (CST)
Received: from sdnp5.ucsd.edu (sdnp5.ucsd.edu [132.239.79.10]) by mailbox1.ucsd.edu (8.8.5/8.6.9) with SMTP id OAA06242 for <xemacs-beta@xemacs.org>; Sun, 2 Mar 1997 14:03:52 -0800 (PST)
Received: by sdnp5.ucsd.edu (SMI-8.6/SMI-SVR4)
	id OAA19306; Sun, 2 Mar 1997 14:06:10 -0800
Sender: dmoore@sdnp5.ucsd.edu
To: XEmacs Beta Mailing List <xemacs-beta@xemacs.org>
Subject: regex.c patch
X-Face: "oX;zS#-JU$-,WKSzG.1gGE]x^cIg!hW.dq>.f6pzS^A+(k!T|M:}5{_%>Io<>L&{hO7W4cicOQ|>/lZ1G(m%7iaCf,6Qgk0%%Bz7b2-W3jd0m_UG\Y;?]}4s0O-U)uox>P3JN)9cm]O\@,vy2e{`3pb!"pqmRy3peB90*2L
Mail-Copies-To: never
Mime-Version: 1.0 (generated by tm-edit 7.105)
Content-Type: text/plain; charset=US-ASCII
From: David Moore <dmoore@ucsd.edu>
Date: 02 Mar 1997 14:06:09 -0800
Message-ID: <rvvi7agd9q.fsf@sdnp5.ucsd.edu>
Lines: 208
X-Mailer: Gnus v5.4.15/XEmacs 20.1


	Fixies up the bug reported by Michael Harnois for backwards
regexp searching under MULE.  Also combines a few duplicated operations
under MULE to speed up some searches in large buffers.  Patch against
20.1b3.

--- regex.c.orig	Sun Mar  2 13:20:45 1997
+++ regex.c	Sun Mar  2 13:20:34 1997
@@ -3819,6 +3819,8 @@
 #ifdef REGEX_BEGLINE_CHECK
   int anchored_at_begline = 0;
 #endif
+  CONST unsigned char *d;
+  Charcount d_size;
 
   /* Check for out-of-range STARTPOS.  */
   if (startpos < 0 || startpos > total_size)
@@ -3826,13 +3828,8 @@
     
   /* Fix up RANGE if it might eventually take us outside
      the virtual concatenation of STRING1 and STRING2.  */
-#if 0
-  if (endpos < -1)
-    range = -1 - startpos;
-#else
   if (endpos < 0)
     range = 0 - startpos;
-#endif
   else if (endpos > total_size)
     range = total_size - startpos;
 
@@ -3880,7 +3877,6 @@
 	  /* whose stupid idea was it anyway to make this
 	     function take two strings to match?? */
 	  int lim = 0;
-	  register CONST unsigned char *d;
 	  int irange = range;
 
 	  if (startpos < size1 && startpos + range >= size1)
@@ -3888,7 +3884,8 @@
 
 	  d = ((CONST unsigned char *)
 	       (startpos >= size1 ? string2 - size1 : string1) + startpos);
-	  DEC_CHARPTR(d);
+	  DEC_CHARPTR(d);	/* Ok, since startpos != size1. */
+	  d_size = charcount_to_bytecount (d, 1);
 
 	  if (translate)
 #ifdef MULE
@@ -3897,14 +3894,16 @@
 	    while (range > lim && translate[*d] != '\n')
 #endif
 	      {
-		INC_CHARPTR(d);
-		range -= charcount_to_bytecount (d, 1);
+		d += d_size;	/* Speedier INC_CHARPTR(d) */
+		d_size = charcount_to_bytecount (d, 1);
+		range -= d_size;
 	      }
 	  else
 	    while (range > lim && *d != '\n')
 	      {
-		INC_CHARPTR(d);
-		range -= charcount_to_bytecount (d, 1);
+		d += d_size;	/* Speedier INC_CHARPTR(d) */
+		d_size = charcount_to_bytecount (d, 1);
+		range -= d_size;
 	      }
 
 	  startpos += irange - range;
@@ -3919,8 +3918,7 @@
 	{
 	  if (range > 0)	/* Searching forwards.  */
 	    {
-	      register CONST unsigned char *d;
-	      register int lim = 0;
+	      int lim = 0;
 	      int irange = range;
 
               if (startpos < size1 && startpos + range >= size1)
@@ -3928,7 +3926,7 @@
 
 	      d = ((CONST unsigned char *)
 		   (startpos >= size1 ? string2 - size1 : string1) + startpos);
-   
+
               /* Written out as an if-else to avoid testing `translate'
                  inside the loop.  */
 	      if (translate)
@@ -3938,23 +3936,25 @@
                 while (range > lim && !fastmap[translate[*d]])
 #endif
 		  {
-		    range -= charcount_to_bytecount (d, 1);
-		    INC_CHARPTR(d);
+		    d_size = charcount_to_bytecount (d, 1);
+		    range -= d_size;
+		    d += d_size; /* Speedier INC_CHARPTR(d) */
 		  }
 	      else
                 while (range > lim && !fastmap[*d])
 		  {
-		    range -= charcount_to_bytecount (d, 1);
-		    INC_CHARPTR(d);
+		    d_size = charcount_to_bytecount (d, 1);
+		    range -= d_size;
+		    d += d_size; /* Speedier INC_CHARPTR(d) */
 		  }
 
 	      startpos += irange - range;
 	    }
 	  else				/* Searching backwards.  */
 	    {
-	      register unsigned char c = (size1 == 0 || startpos >= size1
-					  ? string2[startpos - size1] 
-					  : string1[startpos]);
+	      unsigned char c = (size1 == 0 || startpos >= size1
+				 ? string2[startpos - size1] 
+				 : string1[startpos]);
 #ifdef MULE
 	      if (c < 0x80 && !fastmap[(unsigned char) TRANSLATE (c)])
 #else
@@ -3990,27 +3990,25 @@
     advance:
       if (!range) 
 	break;
-      else {
-	register CONST unsigned char *d;
-	Charcount d_size;
-
-	d = ((CONST unsigned char *)
-	     (startpos >= size1 ? string2 - size1 : string1) + startpos);
-
-	if (range > 0) 
-	  {
-	    d_size = charcount_to_bytecount (d, 1);
-	    range -= d_size;
-	    startpos += d_size;
-	  }
-	else
-	  {
-	    DEC_CHARPTR(d);
-	    d_size = charcount_to_bytecount (d, 1);
-	    range += d_size;
-	    startpos -= d_size;
-	  }
-      }
+      else if (range > 0) 
+	{
+	  d = ((CONST unsigned char *)
+	       (startpos >= size1 ? string2 - size1 : string1) + startpos);
+	  d_size = charcount_to_bytecount (d, 1);
+	  range -= d_size;
+	  startpos += d_size;
+	}
+      else
+	{
+	  /* Note startpos > size1 not >=.  If we are on the
+	     string1/string2 boundary, we want to backup into string1. */
+	  d = ((CONST unsigned char *)
+	       (startpos > size1 ? string2 - size1 : string1) + startpos);
+	  DEC_CHARPTR(d);
+	  d_size = charcount_to_bytecount (d, 1);
+	  range += d_size;
+	  startpos -= d_size;
+	}
     }
   return -1;
 } /* re_search_2 */
@@ -5124,19 +5122,10 @@
                   = *p2 == (unsigned char) endline ? '\n' : p2[2];
 #endif
 
-#if 1
-                /* dmoore@ucsd.edu - emacs 19.34 uses this: */
-
                 if ((re_opcode_t) p1[3] == exactn
                     && ! ((int) p2[1] * BYTEWIDTH > (int) p1[5]
                           && (p2[2 + p1[5] / BYTEWIDTH]
                               & (1 << (p1[5] % BYTEWIDTH)))))
-#else
-                if ((re_opcode_t) p1[3] == exactn
-                    && ! ((int) p2[1] * BYTEWIDTH > (int) p1[4]
-                          && (p2[1 + p1[4] / BYTEWIDTH]
-                              & (1 << (p1[4] % BYTEWIDTH)))))
-#endif
                   {
   		    p[-3] = (unsigned char) pop_failure_jump;
                     DEBUG_PRINT3 ("  %c != %c => pop_failure_jump.\n",
--- ChangeLog.orig	Sun Mar  2 14:02:59 1997
+++ ChangeLog	Sun Mar  2 14:02:42 1997
@@ -1,3 +1,8 @@
+Sun Mar  2 14:01:32 1997  David Moore  <dmoore@ucsd.edu>
+
+	* regex.c (re_search_2): Properly handle crossing the buffer gap
+	when doing a backwards search under MULE.
+
 Wed Feb 26 10:24:40 1997  Steven L Baur  <steve@altair.xemacs.org>
 
 	* Makefile.in.in: make-docfile takes a "-i" parameter to pass



-- 
David Moore <dmoore@ucsd.edu>       | Computer Systems Lab      __o
UCSD Dept. Computer Science - 0114  | Work: (619) 534-8604    _ \<,_
La Jolla, CA 92093-0114             | Fax:  (619) 534-1445   (_)/ (_)
<URL:http://oj.egbt.org/dmoore/>    | In a cloud bones of steel.

