Subject: Re: libssh2 master 37624b6 sftp_attrsize: converted function to a macro

Re: libssh2 master 37624b6 sftp_attrsize: converted function to a macro

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Wed, 28 Apr 2010 08:38:35 +0200 (CEST)

On Wed, 28 Apr 2010, Alexander Lamaison wrote:

>> sftp_attrsize: converted function to a macro
>
>> This way, the macro can evaluate a static number at compile time
>> for two out of four uses, and it probably runs faster for the
>> other two cases too.
>
> Oh please no.
>
> These kind of hand optimisations are almost always useless. Was there any
> other reason for the conversion except performance? If not, was there a
> benchmark to show this was a bottleneck and the macro fixed it?

First, I disagree that these things "are almost always useless".

But my primary motivation for chaning this was that I really didn't like how
the function took a struct pointer as argument and only checked/used the flag
field within the function, and in 50% of the use cases it is a static flag
known at compile-time.

To me, this makes it A LOT clearer that sftp_attrsize() only checks the flag
(and no other attr struct magic is involved) and returns a size based on that.
It being a macro or function is less important then, but I just didn't think a
full function was motivated once I changed the input argument - and a macro
seemed simple and easy enough.

-- 
  / daniel.haxx.se
_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2010-04-28