[DUG] Why re-use when you can duplicate!

Jolyon Smith jsmith at deltics.co.nz
Sun Jun 3 21:03:11 NZST 2012


Arguably it's an optimisation.  This isn't code that is likely to change
and incurring an additional function call for such a small snippet of code
for the kind of processing such checks might be involved in could be a
significant overhead.

They could have "inline"d it I guess, but there are all sorts of things
that seem to break inlining in Delphi (as in "cause to be rejected by the
compiler") and this might fall foul of those.

Another explanation (perhaps also optimisation related) might lie in the
fact that it isn't a perfect duplication... note the slight differences in
the call that the first makes to INTERNALGetUnicodeCategory(UCS4Char),
whilst the second uses GetUnicodeCategory(String, Index).  Then again, this
might also be a sub-optimal variation.  Hard to say without probing deeper
than is warranted at this point.

:)

On 3 June 2012 12:15, Todd <todd.martin.nz at gmail.com> wrote:

> Is this a representative example of the code quality Embarcadero is
> producing today?
>
> class function TCharacter.IsNumber(C: Char): Boolean;
> begin
>  if not IsLatin1(C) then
>    Result := CheckNumber(InternalGetUnicodeCategory(UCS4Char(C)))
>  else if not IsAscii(C) then
>    Result := CheckNumber(InternalGetLatin1Category(C))
>  else
>    Result := (C >= '0') and (C <= '9');
> end;
>
> class function TCharacter.IsNumber(const S: string; Index: Integer):
> Boolean;
> var
>  C: Char;
> begin
>  CheckStringRange(S, Index);
>  C := S[Index];
>  if not IsLatin1(C) then
>    Result := CheckNumber(GetUnicodeCategory(S, Index))
>  else if not IsAscii(C) then
>    Result := CheckNumber(InternalGetLatin1Category(C))
>  else
>    Result := (C >= '0') and (C <= '9');
> end;
>
> Todd.
> _______________________________________________
> NZ Borland Developers Group - Delphi mailing list
> Post: delphi at listserver.123.net.nz
> Admin: http://delphi.org.nz/mailman/listinfo/delphi
> Unsubscribe: send an email to delphi-request at listserver.123.net.nz with
> Subject: unsubscribe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://listserver.123.net.nz/pipermail/delphi/attachments/20120603/005450bf/attachment.html 


More information about the Delphi mailing list