Re: [PATCH 01/17] btrfs-progs: Unify size-parsing

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2/25/13 5:26 PM, Zach Brown wrote:
>>  		case 'e':
>>  			mult *= 1024;
>> +			/* Fallthrough */
> 
> These comments still annoy me :).  

it shuts up coverity & other static checkers which are worried about
a missing break...

> And really, that code kind of annoys
> me too.  That's a lot of duplicated code for a mapping of characters to
> powers of 1024.
> 
> How about.. 
> 
> u64 pow_u64(u64 x, unsigned y)
> {
> 	u64 ret = 1;
> 
> 	while (y--)
> 		ret *= x;
> 
> 	return ret;
> }
> 
> u64 get_mult(char unit)
> {
> 	static char *units = "bkmgtpe";
> 	char *found = index(units, unit);
> 
> 	if (found)
> 		return pow_u64(1024, found - units);
> 	return 0;
> }
> 
> Seems like a lot less noise for the same functionality.

If you want to submit that patch as a further cleanup I'd review it ;)

But TBH (going out on a limb crossing Zach here ;) my feeble brain
is easily confused by your clever code.  I'd rather just do the
simple thing simply...

-Eric

> - z
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Filesystem Development]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux