comp.lang.ada
 help / color / mirror / Atom feed
From: rieachus@comcast.net
Subject: Re: Ada.Strings.Fixed.Count raises Storage_Error
Date: Sun, 26 Jun 2016 21:00:05 -0700 (PDT)
Date: 2016-06-26T21:00:05-07:00	[thread overview]
Message-ID: <b8525924-a968-43bb-b6f0-4db112c8ef1c@googlegroups.com> (raw)
In-Reply-To: <nkpri6$odg$1@dont-email.me>

On Sunday, June 26, 2016 at 8:21:29 PM UTC-4, Jeffrey R. Carter wrote:
 
> While I mostly agree, this one, given the code presented earlier, is a 1-line
> change to correct, which hardly seems like it would make developers' lives
> miserable:
> 
>     while Ind <= Source'Last loop
>        if Pattern = Source (Ind .. Ind) then
>           ...
>        else
>           Ind := Ind + 1;
>        end if;
>     end loop;
> 
> Add
> 
> exit when Ind = Integer'Last;
> 
> after "else". I see no reason this code shouldn't correctly handle this corner case.

It is not a one-line change.  There is documentation, adding cases to regression test libraries, and finally the effort on the developer's part to fix this without producing significantly slower code.  How many times will that extra line be executed if the string is large, but does not end at Integer'Last?  This is extremely important since it is a branch in an innermost loop.  If I were responsible for fixing this I would hoist the case of strings with S'Last = Integer'Last up as high as possible, even if it required (almost) duplicating a lot of code.

This tradeoff between performance and corner cases has been made before.  Try writing a loop that runs from X to Y for some non-static values, then test the code when X = Integer'First and Y = Integer'Last.  You may want to print a period for each 100 million times around the loop...

Do the same thing for a large unsigned array with static bounds of U'First and and U'Last.  This case should work as expected.  Why?  Because looping over the entire range of an unsigned type is something that occurs often in radar, hash tables, and other cases. On a 64-bit machine it probably will not exit if you have the largest possible unsigned type, though I don't know how you could tell. (Even if you could do each interation in a nanosecond, that would take over 500 years...)

  reply	other threads:[~2016-06-27  4:00 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-12 11:36 Ada.Strings.Fixed.Count raises Storage_Error Xavier Petit
2016-05-12 15:22 ` Tero Koskinen
2016-05-12 22:05 ` Georg Bauhaus
2016-06-26 21:18   ` Victor Porton
2016-06-26 23:23     ` rieachus
2016-06-27  0:21       ` Jeffrey R. Carter
2016-06-27  4:00         ` rieachus [this message]
2016-06-27  0:51       ` Xavier Petit
2016-06-27  4:48         ` rieachus
2016-06-28 18:25           ` Xavier Petit
2016-06-29 18:49           ` Niklas Holsti
2016-06-29 19:40             ` Jeffrey R. Carter
2016-06-29 19:57             ` Dmitry A. Kazakov
2016-07-01 11:48               ` rieachus
2016-07-01 13:08                 ` Dmitry A. Kazakov
2016-06-27  8:29       ` Simon Wright
2016-06-27  8:41         ` Georg Bauhaus
2016-06-29  8:15       ` Niklas Holsti
2016-06-29  9:13         ` J-P. Rosen
2016-06-29 17:43           ` Niklas Holsti
2016-06-29 18:19             ` J-P. Rosen
2016-06-29 20:30             ` Robert A Duff
2016-06-30  5:38               ` Niklas Holsti
2016-07-01 10:40                 ` rieachus
2016-07-01 10:55                   ` J-P. Rosen
2016-07-01 12:17                     ` rieachus
2016-07-01 12:55                       ` G.B.
2016-06-27 12:52     ` Victor Porton
2016-05-12 22:56 ` Randy Brukardt
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox