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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!1.eu.feeder.erje.net!feeder.erje.net!2.us.feeder.erje.net!bloom-beacon.mit.edu!bloom-beacon.mit.edu!newsswitch.lcs.mit.edu!nntp.TheWorld.com!.POSTED!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Introductory Presentations, especially aimed at C++ programmers! Date: Tue, 13 Dec 2016 17:52:05 -0500 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <1905815374.502825168.454102.laguest-archeia.com@nntp.aioe.org> <877f7b5llo.fsf@nightsong.com> NNTP-Posting-Host: shell02.theworld.com Mime-Version: 1.0 Content-Type: text/plain X-Trace: pcls7.std.com 1481669525 22074 192.74.137.72 (13 Dec 2016 22:52:05 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Tue, 13 Dec 2016 22:52:05 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:zqa/aPsWfjQRuu5hEblg4GkvE2g= Xref: news.eternal-september.org comp.lang.ada:32797 Date: 2016-12-13T17:52:05-05:00 List-Id: "Jeffrey R. Carter" writes: > Yes, but the GNAT implementation is rather poor. It depends on whether you care about very long lines. If so, you want to double the buffer size each time (or similar). If the line is a million characters, the GNAT version does around 20 recursive calls, whereas the version below does around 1000 recursive calls. I'm too lazy to measure the speed, and anyway, the computation might be swamped by the disk access. Text_IO should be (should have been!) designed for convenience, not efficiency. You don't call Text_IO in the inner loops of an embedded real-time system. ;-) >... A better way doesn't > need to copy anything: You can't do "return Buffer & Get_Line;" without some copying. I'm willing to believe that GNAT does more copying than is absolutely necessary. > function Get_Line return String is > Buffer : String (1 .. 1_000); > Last : Natural; > begin -- Get_Line > Get_Line (Item => Buffer, Last => Last); > > if Last < Buffer'Last then > return Buffer (1 .. Last); > end if; > > return Buffer & Get_Line; > end Get_Line; - Bob