🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.pascal.borland
Article #549

Re: Speed of Delete - improvement

#549
From: Mike
Date: Tue, 18 Nov 1997 00:00
61 lines
2063 bytes
Dr John Stockton wrote:
> 
> Copy to AAO & TS by E-mail; news:c.l.p.b,c.l.p.m,b.p.t.
> 
> As a result of E-mails (on different subjects) exchanged with TS and
> with AAO, I have given a little thought to the Delete routine (for
> string-handling).
> 
> It seems to me that Delete is sometimes implemented as Copy(Start),
> Copy(Tail), Concat(Start, Tail); and that there should be a better way
> just involving Move(Tail).

[...]

> The present routine is :
>   procedure JDelete(var S: String; Index: Integer; Count:Integer);
>   var Tmp : integer ;
>   begin
>     if (Count<=0) or (Index<=0) or (Index>Length(S)) then EXIT ;
>     if Index+Count-1>Length(S) then Count := Length(S)-Index+1 ;
>     Tmp := Length(S)-Index-Count+1 ;
>     if Tmp>0 then Move(S[Index+Count], S[Index], Tmp) ;
>     Dec(S[0], Count) end {JDelete} ;

[...]

Here's mine!

procedure DelSt
  (
  var st : string;
  ix     : byte;
  count  : byte
  );

var
  gv    : word;		{got to handle strings of 255 char}
  StLen : byte absolute st;

  begin
    gv := ix + count;

    if (StLen >= gv) then
    begin
      move(st[gv], st[ix], StLen + 1 - gv);
      dec(StLen, count);
    end
    else
    StLen := ix - 1;
  end;

Best Regards,

Mike
CEO, Analog & Digital Design
Automated Production Test
  http://www.csolve.net/~add/home.htm

Hosting Jonathan Ramsey's Pascal TCP/IP for DOS:
  http://www.csolve.net/~add/zips/tcp.htm
Technical Details
Message-ID: <347171D0.537@short.net>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <s2qpaAAJUIc0EwPB@merlyn.demon.co.uk>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10261c,9e270db731f7d69c
X-Google-Attributes: gid10261c,public
X-Google-Thread: 108ebd,9e270db731f7d69c
X-Google-Attributes: gid108ebd,public
X-Google-Thread: 111659,9e270db731f7d69c
X-Google-Attributes: gid111659,public
From: Mike <internal@short.net>
Subject: Re: Speed of Delete - improvement
Date: 1997/11/18
Message-ID: <347171D0.537@short.net>
X-Deja-AN: 290372974
References: <s2qpaAAJUIc0EwPB@merlyn.demon.co.uk>
Organization: UTS
Newsgroups: comp.lang.pascal.borland,comp.lang.pascal.misc,borland.public.turbopascal