[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Devel] suggested improvement to FT_Add64
From: |
David Turner |
Subject: |
Re: [Devel] suggested improvement to FT_Add64 |
Date: |
Fri, 12 Oct 2001 10:24:29 +0200 |
Hello Graham,
Graham Asher a écrit :
>
> This might be said to be nitpicking, but there is a small improvement to be
> made to FT_Add64, which might save a cycle or two:
>
> replace
>
> FT_EXPORT_DEF( void ) FT_Add64( FT_Int64* x,
> FT_Int64* y,
> FT_Int64 *z )
> {
> register FT_UInt32 lo, hi;
>
> lo = x->lo + y->lo;
> hi = x->hi + y->hi + ( lo < x->lo );
>
> z->lo = lo;
> z->hi = hi;
> }
>
> with
>
> FT_EXPORT_DEF( void ) FT_Add64( FT_Int64* x,
> FT_Int64* y,
> FT_Int64 *z )
> {
> z->lo = x->lo + y->lo;
> z->hi = x->hi + y->hi + (z->lo < x->lo );
> }
>
> There is no need for the local variables. Anything gained by the use of a
> local variable 'lo' instead of 'z->lo', which is used twice, would surely be
> lost by the extra assignments to 'lo' and 'z->lo'. And 'register' is
> irrelevant to modern compilers.
>
Graham, your code is _not_ equivalent to the original one.
Indeed, it will produce incorrect results when "z == x"..
Second, FreeType is only used with not so modern compilers in the
embedded market, and a "register" here is not going to cost you
anything for more recent ones anyway..
And any modern compiler is going to get rid of the "hi" local
variable anyway, so I don't think we need to optimize the hell
out of this code..
Regards,
- David