|
From: | Graydon Hoare |
Subject: | Re: xdelta speedups (was Re: [Monotone-devel] updates to net.venge.monotone.experiment.performance) |
Date: | Thu, 10 Aug 2006 11:02:11 -0400 |
User-agent: | Thunderbird 1.5.0.5 (Windows/20060719) |
Eric Anderson wrote:
My best guess was that widen was there to make sure that when widening a signed to an unsigned the right thing happened, but I wasn't sure it seemed unnecessary for an unsigned to unsigned widen.
Yup.The main part of the function actually is the "implicitly convert to the explicit widen<>() argument type, to use in the explicit conversion" part. If you just do static_cast<u32>(somestring[i]) you are doing a sign extension on a platform with signed chars, because somestring[i] has char type.
You could write static_cast<u32>(static_cast<u8>(somestring[i])) instead, but I felt like widen<u32,u8>(somestring[i]) was more pleasant on the eyes.
(I don't actually know that static_cast<u32>(u8) is guaranteed to not sign-extend, because I can't find a precise definition of the conversion rules; but I'd be pretty surprised if there was a platform anywhere where it did. It's probably OK to assume unless it's in netsync code, where "being wrong" means "buffer overrun")
-graydon
[Prev in Thread] | Current Thread | [Next in Thread] |