Messages in this thread | | | Subject | Re: [PATCH] consolidate all within() implementations | From | Peter 1 Oberparleiter <> | Date | Wed, 21 May 2008 12:33:40 +0200 |
| |
Peter Zijlstra <a.p.zijlstra@chello.nl> wrote on 21.05.2008 12:04:26: > > +static inline int addr_within_len(const void *addr, const void *start, > > + size_t len) > > +{ > > + return ((unsigned long) addr >= (unsigned long) start) && > > + ((unsigned long) addr < ((unsigned long) start + len)); > > +} > > might be my braindamage, but I'd have written it like: > > static inline int > addr_within_len(const void *addr, const void *start, size_t len) > { > return (unsigned long)addr - (unsigned long)start < len; > }
Definitely another way to put it. In my opinion the intention of the implementation is more easily understood though when spelling it out as (a>=b) && (a<c).
> static inline int > addr_within(const void *add, const void *start, const void *end) > { > return addr_within_len(addr, start, > (unsigned long)end - (unsigned long)start); > }
For empty ranges (start > end), this produces different (less expected) results than the previous version.
Regards, Peter
| |