🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Speed of Delete - improvement

#552
From: Pedt Scragg
Date: Tue, 18 Nov 1997 00:00
40 lines
2031 bytes
In article <DBS2jCAmrdc0Ew4E@merlyn.demon.co.uk>, Dr John Stockton
<jrs@merlyn.demon.co.uk> writes
>In article <s2qpaAAJUIc0EwPB@merlyn.demon.co.uk> of Mon, 17 Nov 1997
>17:55:21 in comp.lang.pascal.borland, Dr John Stockton
><jrs@merlyn.demon.co.uk> wrote:
>>...   I have given a little thought to the Delete routine (for
>>string-handling).
>> ...
>
>Today's routine is nicer and a bit faster than yesterday's :-
>
>  procedure Remove(var S : string ; Index, Count : Integer) ;
>  { JRS's faster replacement for Sys.DELETE }
>  var Tmp : integer ;
>  begin
>    if (Count<=0) or (Index<=0) or (Index>Length(S)) then EXIT ;
>    Tmp := Length(S)-Index+1 { Maximum Removable } ;
>    if Count>=Tmp then Count := Tmp else
>      Move(S[Index+Count], S[Index], Tmp-Count) ;
>    Dec(S[0], Count) end {Remove} ;
>
How about:

PROCEDURE remove(VAR s : String; index, count : byte);
BEGIN
  if index > length(s) then exit else
  if index + count > succ(length(s)) then s[0]:= chr(index) else
  begin
       Move(s[Index + count],s[Index],succ(length(s)) - index - count);
       Dec(s[0], Count);
  end;
END;


-- 
Pedt Scragg <postmaster@pedt.demon.co.uk>

In principle,   is there uncertainty that
Heisenberg was working his best in chaos?
Technical Details
Message-ID: <Mj9fjAAGehc0EwaJ@pedt.demon.co.uk>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <s2qpaAAJUIc0EwPB@merlyn.demon.co.uk> <DBS2jCAmrdc0Ew4E@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: 111659,9e270db731f7d69c
X-Google-Attributes: gid111659,public
X-Google-Thread: 108ebd,9e270db731f7d69c
X-Google-Attributes: gid108ebd,public
From: Pedt Scragg <postmaster@pedt.demon.co.uk>
Subject: Re: Speed of Delete - improvement
Date: 1997/11/18
Message-ID: <Mj9fjAAGehc0EwaJ@pedt.demon.co.uk>
X-Deja-AN: 290566374
References: <s2qpaAAJUIc0EwPB@merlyn.demon.co.uk> <DBS2jCAmrdc0Ew4E@merlyn.demon.co.uk>
Distribution: world
X-NNTP-Posting-Host: pedt.demon.co.uk [194.222.191.220]
Organization: Working in Chaos
Newsgroups: comp.lang.pascal.borland,comp.lang.pascal.misc,borland.public.turbopascal