[PATCH] osutil: implementation for Win32

Matt Mackall mpm at selenic.com
Tue Sep 9 21:58:50 UTC 2008


On Tue, 2008-09-09 at 17:10 -0400, Petr Kodl wrote:
> Benoit - sorry for sending the reply twice - missed the reply all  
> 
> 
>         > +static int to_python_time(FILETIME* ms_time)
>         > +{
>         > +       /* this is number of 100-nanoseconds between epoch
>         and January 1 1601 */
>         > +       static __int64 a0 = (__int64)134774L * (__int64)24L
>         > +                                               *
>         (__int64)3600L * (__int64)1000L
>         > +                                               *
>         (__int64)1000L * (__int64)10L;
>         > +       /* conversion factor back to 1s resolution required
>         by Python ctime */
>         > +       static __int64 a1 = 1000 * 1000 * 10;
>         
>         
>         good point - I'll change it 
>         
>         > +       __int64 tmp;
>         > +       memcpy(&tmp, ms_time, sizeof(__int64));
>         
>         
>         why not directly return (int)(*ms_time - a0)/a1 ?
> 
> potential alignment  problem by direct pointer cast 
> http://blogs.msdn.com/oldnewthing/archive/2004/08/25/220195.aspx 

You could be clever and put your FIND_DATA structure inside another
structure that forced alignment. Or you could simply do:

return ((((__int 64)date.hi << 32) + date.lo) - offset) / scale;

..which any sensible compiler will optimize quite nicely.

Note that you can also divide by 10M first, which makes your offset less
ungainly.

-- 
Mathematics is the supreme nostalgia of our time.




More information about the Mercurial-devel mailing list