Ignore:
Timestamp:
Oct 24, 2010, 11:53:21 AM (15 years ago)
Author:
Patrick Gansterer
Message:

2010-10-24 Patrick Gansterer <Patrick Gansterer>

Reviewed by David Kilzer.

Inline WTF::bitwise_cast and fix style
https://bugs.webkit.org/show_bug.cgi?id=48208

  • wtf/StdLibExtras.h: (WTF::bitwise_cast): (WTF::bitCount):
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/wtf/StdLibExtras.h

    r65311 r70419  
    8888namespace WTF {
    8989
    90     /*
    91      * C++'s idea of a reinterpret_cast lacks sufficient cojones.
    92      */
    93     template<typename TO, typename FROM>
    94     TO bitwise_cast(FROM from)
    95     {
    96         COMPILE_ASSERT(sizeof(TO) == sizeof(FROM), WTF_bitwise_cast_sizeof_casted_types_is_equal);
    97         union {
    98             FROM from;
    99             TO to;
    100         } u;
    101         u.from = from;
    102         return u.to;
    103     }
     90/*
     91 * C++'s idea of a reinterpret_cast lacks sufficient cojones.
     92 */
     93template<typename TO, typename FROM>
     94inline TO bitwise_cast(FROM from)
     95{
     96    COMPILE_ASSERT(sizeof(TO) == sizeof(FROM), WTF_bitwise_cast_sizeof_casted_types_is_equal);
     97    union {
     98        FROM from;
     99        TO to;
     100    } u;
     101    u.from = from;
     102    return u.to;
     103}
    104104
    105     // Returns a count of the number of bits set in 'bits'.
    106     inline size_t bitCount(unsigned bits)
    107     {
    108         bits = bits - ((bits >> 1) & 0x55555555);
    109         bits = (bits & 0x33333333) + ((bits >> 2) & 0x33333333);
    110         return (((bits + (bits >> 4)) & 0xF0F0F0F) * 0x1010101) >> 24;
    111     }
     105// Returns a count of the number of bits set in 'bits'.
     106inline size_t bitCount(unsigned bits)
     107{
     108    bits = bits - ((bits >> 1) & 0x55555555);
     109    bits = (bits & 0x33333333) + ((bits >> 2) & 0x33333333);
     110    return (((bits + (bits >> 4)) & 0xF0F0F0F) * 0x1010101) >> 24;
     111}
    112112
    113113} // namespace WTF
    114114
    115 #endif
     115#endif // WTF_StdLibExtras_h
Note: See TracChangeset for help on using the changeset viewer.