🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.emacs.bug
Article #99323

Speeding up buffer modifications

#99323
From: Piercarlo Grandi
Date: Tue, 25 Sep 1990 17:39
123 lines
4196 bytes
I am reposting here a little patch to "insdel.c" that will dramatically
speed up the shifting of the gap. All of the other catastrophic
performance problems of using a buffer gap system, principally the fact
that it practically requires the entire buffer to be core resident or
else..., are not addressed, but at least gap shifts are no longer
performed one character at a time, and CPU time goes down a lot.

This patch comes in especially handy now as I have posted to comp.arch
and alt.sources a very portable, very efficient version of memcpy(3) or
bcopy(3) that beats them hands down on many architectures when copying
between unaligned addresses, e.g. most of the cases that the gap has to
be shifted.

You will want to provide suitable #define's for BSTRING_LTOR,
BSTRING_RTOL, bcopy in you s-*.h file, unless you are running a BSD-ish
system in which case the supplied defaults will be OK. You still havwe
to define BSTRING to enable everything.

RCS file: insdel.c,v
retrieving revision 18.55
diff -c -r18.55 insdel.c
*** /tmp/,RCSt1a10289	Mon Aug  6 22:52:45 1990
--- insdel.c	Mon Aug  6 11:43:57 1990
***************
*** 24,29 ****
--- 24,44 ----
  #include "buffer.h"
  #include "window.h"
  
+ #ifdef BSTRING
+ # ifdef BSTRING_LTOR
+ #   undef BSTRING_LTOR
+ #   define BSTRING_LTOR 1
+ # else
+ #   define BSTRING_LTOR 0
+ # endif
+ # ifdef BSTRING_RTOL
+ #   undef BSTRING_RTOL
+ #   define BSTRING_RTOL 1
+ # else
+ #   define BSTRING_RTOL 0
+ # endif
+ #endif
+ 
  /* Move gap to position `pos'.
     Note that this can quit!  */
  
***************
*** 33,38 ****
--- 48,58 ----
    if (bf_p2 != bf_gap + bf_p1)
      abort ();
  
+   /*
+     if pos == bs_s1 then the gap does not need moving at all. Remember
+     that bs_s1 points to 1 *below* the real start of the gap.
+   */
+ 
    if (pos <= bf_s1)
      gap_left (pos);
    else if (pos > bf_s1 + 1)
***************
*** 86,91 ****
--- 106,121 ----
        if (i > 32000)
  	i = 32000;
        new_s1 -= i;
+ #if defined(BSTRING)
+       /*
+         We are moving the gap to the left; this means moving
+ 	memory to the right (from <= to), and overlaps are safe
+ 	if we copy from right to left.
+       */
+       if (i >= 32 && (BSTRING_RTOL || /* no overlap */ from <= to-i))
+ 	from -= i, to -= i, (void) bcopy (from,to,i);
+       else
+ #endif
        while (--i >= 0)
  	*--to = *--from;
      }
***************
*** 146,151 ****
--- 176,192 ----
        if (i > 32000)
  	i = 32000;
        new_s1 += i;
+ 
+ #ifdef BSTRING
+       /*
+         We are moving the gap to the right; this means moving
+ 	memory to the left (to <= from), and overlaps are safe
+ 	if we copy from left to right.
+       */
+       if (i >= 32 && (BSTRING_LTOR || /* no overlap */ to+i <= from))
+ 	(void) bcopy (from,to,i), from += i, to += i;
+       else
+ #endif
        while (--i >= 0)
  	*to++ = *from++;
      }
***************
*** 204,210 ****
    if (bf_gap >= k)
      return;
  
!   k += 2000;			/* Get more than just enough */
  
    p1 = (unsigned char *) realloc (bf_p1 + 1, bf_s1 + bf_s2 + k);
    if (p1 == 0)
--- 245,251 ----
    if (bf_gap >= k)
      return;
  
!   k += 32000;			/* Get more than just enough */
  
    p1 = (unsigned char *) realloc (bf_p1 + 1, bf_s1 + bf_s2 + k);
    if (p1 == 0)

--
Piercarlo "Peter" Grandi           | ARPA: pcg%uk.ac.aber.cs@nsfnet-relay.ac.uk
Dept of CS, UCW Aberystwyth        | UUCP: ...!mcsun!ukc!aber-cs!pcg
Penglais, Aberystwyth SY23 3BZ, UK | INET: pcg@cs.aber.ac.uk
Technical Details
Message-ID: <PCG.90Sep25183943@odin.cs.aber.ac.uk>
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!ukc!dcl-cs!aber-cs!athene!pcg

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: fb2f1,61695c7a89774c43,start
X-Google-Attributes: gidfb2f1,public
X-Google-ArrivalTime: 1990-09-25 10:39:43 PST
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!ukc!dcl-cs!aber-cs!athene!pcg
From: pcg@cs.aber.ac.uk (Piercarlo Grandi)
Newsgroups: gnu.emacs.bug
Subject: Speeding up buffer modifications
Message-ID: <PCG.90Sep25183943@odin.cs.aber.ac.uk>
Date: 25 Sep 90 17:39:43 GMT
Sender: pcg@aber-cs.UUCP
Distribution: gnu
Organization: Coleg Prifysgol Cymru
Lines: 123
Posted: Tue Sep 25 18:39:43 1990
Nntp-Posting-Host: odin