comp.lang.ada
 help / color / mirror / Atom feed
From: kenner@lab.ultra.nyu.edu (Richard Kenner)
Subject: Re: Most efficient way to check for null string?
Date: 1997/06/23
Date: 1997-06-23T00:00:00+00:00	[thread overview]
Message-ID: <5oln1e$f4f$1@news.nyu.edu> (raw)
In-Reply-To: dewar.866897158@merv


In article <dewar.866897158@merv> dewar@merv.cs.nyu.edu (Robert Dewar) writes:
>>...If you really want to
>>shave cycles, the following will likely be the most efficient:
>>
>>     if Str'Last < Str'First then ...
>
>Bletch.  That's the least readable of all, but Tucker's right that it
>might be more efficient.  Tucker didn't say why.  It's because Ada
>(foolishly, IMHO) allows Str's range to be something like
>1_000 .. -1_000_000.  Which means that calculating the 'Length involves
>a conditional jump in the general case.

That's true, but the condition on the conditional jump is precisely the
same as the condition of the string being null, so the tests should be
equivalent.  Out of curiousity, I checked to see what GNAT will do.  It
neither optimized it to the above test, nor did the general computation of
'Length (involving conditional jumps) and tested its resul, but instead
simply did the above test twice in a row!

That redundant test should have been eliminated by the GCC optimizer
and I just put on my list to find out one of these days why it wasn't.




  parent reply	other threads:[~1997-06-23  0:00 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-06-20  0:00 Most efficient way to check for null string? Dale Stanbrough
1997-06-20  0:00 ` Tucker Taft
1997-06-21  0:00   ` Robert A Duff
1997-06-21  0:00     ` Robert Dewar
1997-06-23  0:00       ` Tucker Taft
1997-06-23  0:00       ` Richard Kenner [this message]
1997-06-20  0:00 ` Robert A Duff
1997-06-20  0:00   ` Robert Dewar
replies disabled

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