🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Speed of Delete - improvement

#546
From: Dr John Stockton
Date: Mon, 17 Nov 1997 00:00
43 lines
2615 bytes
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).

A test program of such a routine, in standard BP7 DOS mode, has shown a
speed improvement (in comparison with the library version) of over 50%
with all four run-time checks ON, and of over 200% (3*) with checks off. 
Possible minor optimisations are visible.  Moreover, if the Move method
is carefully implemented in Assembler, as BP7 Delete is, it could
possibly become yet better.

The present routine, with checks off, now persistently gives the same
result as Delete, testing Proc(S, j, k) with S[0], j, k being random;
but I cannot yet claim that the results are infallibly always identical
- though it should be possible to make them so.

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} ;


The current test program should be in 
        http://www.merlyn.demon.co.uk/programs/del_timr.pas
by the time you read this - and may change at any time.
 
-- 
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: <s2qpaAAJUIc0EwPB@merlyn.demon.co.uk>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10261c,9e270db731f7d69c,start
X-Google-Attributes: gid10261c,public
X-Google-Thread: 111659,9e270db731f7d69c,start
X-Google-Attributes: gid111659,public
X-Google-Thread: 108ebd,9e270db731f7d69c,start
X-Google-Attributes: gid108ebd,public
From: Dr John Stockton <jrs@merlyn.demon.co.uk>
Subject: Speed of Delete - improvement
Date: 1997/11/17
Message-ID: <s2qpaAAJUIc0EwPB@merlyn.demon.co.uk>
X-Deja-AN: 290223974
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