From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,4fbd260da735f6f4 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!news4.google.com!proxad.net!news.in2p3.fr!in2p3.fr!news.ecp.fr!news.jacob-sparre.dk!pnx.dk!not-for-mail From: Jacob Sparre Andersen Newsgroups: comp.lang.ada Subject: Re: Copying string slices before calling subroutines? Date: Sat, 05 May 2007 09:33:26 +0200 Organization: Jacob's private Usenet server Message-ID: References: <0hj5339mjmond132qhbn2o01unurs61lbj@4ax.com> <1178091967.392381.282510@o5g2000hsb.googlegroups.com> <5dv3wh6scrh1.2986pbvdw8y2$.dlg@40tude.net> <4oppvmc6anir.g0mz9mrahmdo.dlg@40tude.net> <4akrg4-mot.ln1@newserver.thecreems.com> NNTP-Posting-Host: taasingegade.news.jacob-sparre.dk Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: jacob-sparre.dk 1178350407 16687 85.82.239.166 (5 May 2007 07:33:27 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Sat, 5 May 2007 07:33:27 +0000 (UTC) User-Agent: Gnus/5.110006 (No Gnus v0.6) Emacs/21.4 (gnu/linux) Cancel-Lock: sha1:LcMYtT1MsJk/qSgpGixweCmN3r8= Xref: g2news1.google.com comp.lang.ada:15561 Date: 2007-05-05T09:33:26+02:00 List-Id: Simon Wright writes: > Jeffrey Creem writes: >> function Index >> (Source : String; >> Pattern : String; >> Going : Direction := Forward; >> Mapping : Maps.Character_Mapping := Maps.Identity) return Natural >> is >> Cur_Index : Natural; >> Mapped_Source : String (Source'Range); > > There's the problem that I had (in my case Source'Length was > > 2_000_000!) calling Index from one of my tasks. > > My reworking begins [...] > which calls Ada.Strings.Maps.Value rather more often than I suppose > it could. But since the normal case is for the mapping to be the > identity mapping the most useful optimisation would be to check for > Identity and just compare directly. Wouldn't the proper solution be to separate out Mapping = Maps.Identity and Mapping /= Maps.Identity? Even though we can do cool things with default values for arguments, it isn't always efficient. function Index (Source : String; Pattern : String; Going : Direction := Forward) return Natural; function Index (Source : String; Pattern : String; Going : Direction := Forward; Mapping : Maps.Character_Mapping) return Natural; I can't see that there can be any cases, where existing code will work differently with these two specifications instead of the existing single specification. We should also remember that for a compiler writer team, Mapping = Maps.Identity may not be the normal case. > Someone else was asking whether GNAT copies on the stack before the > call -- I see no evidence of that. Now that the implementation of Index has been pointed out to me, I agree. I could just see that it happened at some point during the call to Index. Greetings, Jacob -- �For there are only two reasons why war is made against a republic: The one, to become lord over her: the other, the fear of being occupied by her.� -- Nicolo Machiavelli