🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Speed of Delete - improvement

#556
From: Dr John Stockton
Date: Wed, 19 Nov 1997 00:00
52 lines
2975 bytes
In article <Mj9fjAAGehc0EwaJ@pedt.demon.co.uk> of Tue, 18 Nov 1997
22:32:38 in comp.lang.pascal.borland, Pedt Scragg
<postmaster@pedt.demon.co.uk> wrote:
>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;

That has an incompatible parameter list, and will go SPLAT if Index<0 or
Count<0 or Index>255 or Count>255; and so cannot always be used as a
replacement for Sys.Delete (some programs may rely on surviving these).
Otherwise, it looks much like Mike's, should have similar performance to
ours; I'll pop it in my program, but some of the comments I posted about
Mike's will apply.

One of the GNU Pascal BP Compatibility people has copies, and has
modified for the GNU compiler by just changing Dec(S[0]) to suit.
 
-- 
John Stockton, Surrey, UK.    jrs@merlyn.demon.co.uk    Turnpike v1.12    MIME.
  Web URL: http://www.merlyn.demon.co.uk/ - FAQqish topics, acronyms and links.
  Correct 4-line sig separator is as above, a line comprising "-- " (SoRFC1036)
  Before a reply, quote with ">" / "> ", known to good news readers (SoRFC1036)
Technical Details
Message-ID: <0dhDgGAl9ic0EwO7@merlyn.demon.co.uk>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <s2qpaAAJUIc0EwPB@merlyn.demon.co.uk> <DBS2jCAmrdc0Ew4E@merlyn.demon.co.uk> <Mj9fjAAGehc0EwaJ@pedt.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: Dr John Stockton <jrs@merlyn.demon.co.uk>
Subject: Re: Speed of Delete - improvement
Date: 1997/11/19
Message-ID: <0dhDgGAl9ic0EwO7@merlyn.demon.co.uk>
X-Deja-AN: 290662110
References: <s2qpaAAJUIc0EwPB@merlyn.demon.co.uk> <DBS2jCAmrdc0Ew4E@merlyn.demon.co.uk> <Mj9fjAAGehc0EwaJ@pedt.demon.co.uk>
Distribution: world
X-NNTP-Posting-Host: merlyn.demon.co.uk [158.152.233.145]
Organization: Home, Surrey, UK
Newsgroups: comp.lang.pascal.borland,comp.lang.pascal.misc,borland.public.turbopascal