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

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

 



>  		case 'e':
>  			mult *= 1024;
> +			/* Fallthrough */

These comments still annoy me :).  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.

- 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