Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r61694 - sandbox/hash/boost/hash
From: me22.ca+boost_at_[hidden]
Date: 2010-04-29 23:17:16


Author: smcmurray
Date: 2010-04-29 23:17:15 EDT (Thu, 29 Apr 2010)
New Revision: 61694
URL: http://svn.boost.org/trac/boost/changeset/61694

Log:
hash: clean up the packer specializations to use fewer auxillary parameters
Text files modified:
   sandbox/hash/boost/hash/pack.hpp | 97 +++++++++++++++++++--------------------
   1 files changed, 47 insertions(+), 50 deletions(-)

Modified: sandbox/hash/boost/hash/pack.hpp
==============================================================================
--- sandbox/hash/boost/hash/pack.hpp (original)
+++ sandbox/hash/boost/hash/pack.hpp 2010-04-29 23:17:15 EDT (Thu, 29 Apr 2010)
@@ -25,16 +25,14 @@
 template <typename Endianness,
           int InputBits, int OutputBits,
           bool Explode = (InputBits > OutputBits),
- bool Implode = (InputBits < OutputBits),
- bool BytesOnly = (InputBits % CHAR_BIT == 0 &&
- OutputBits % CHAR_BIT == 0),
- bool Prefer = true>
-struct packer;
+ bool Implode = (InputBits < OutputBits)>
+struct real_packer;
 
 template <typename Endianness,
- int Bits,
- bool BytesOnly>
-struct packer<Endianness, Bits, Bits, false, false, BytesOnly, false> {
+ int Bits>
+struct real_packer<Endianness,
+ Bits, Bits,
+ false, false> {
 
     template <typename OutputType, typename InputType>
     static OutputType pack_array(InputType const &in) {
@@ -50,11 +48,10 @@
 };
 
 template <typename Endianness,
- int InputBits, int OutputBits,
- bool BytesOnly>
-struct packer<Endianness,
- InputBits, OutputBits,
- true, false, BytesOnly, false> {
+ int InputBits, int OutputBits>
+struct real_packer<Endianness,
+ InputBits, OutputBits,
+ true, false> {
 
     BOOST_STATIC_ASSERT(InputBits % OutputBits == 0);
 
@@ -75,11 +72,10 @@
 };
 
 template <typename Endianness,
- int InputBits, int OutputBits,
- bool BytesOnly>
-struct packer<Endianness,
- InputBits, OutputBits,
- false, true, BytesOnly, false> {
+ int InputBits, int OutputBits>
+struct real_packer<Endianness,
+ InputBits, OutputBits,
+ false, true> {
 
     BOOST_STATIC_ASSERT(OutputBits % InputBits == 0);
 
@@ -99,51 +95,52 @@
 
 };
 
-// Forward Prefer to !Prefer if nothing better matches
+// Forward if nothing better matches
 template <typename Endianness,
           int InputBits, int OutputBits,
- bool Explode, bool Implode, bool BytesOnly>
-struct packer<Endianness,
- InputBits, OutputBits,
- Explode, Implode, BytesOnly, true>
- : packer<Endianness,
- InputBits, OutputBits,
- Explode, Implode, BytesOnly, false> {};
+ bool BytesOnly = !(InputBits % CHAR_BIT) && !(OutputBits % CHAR_BIT)>
+struct packer : real_packer<Endianness, InputBits, OutputBits> {};
 
 #ifndef BOOST_HASH_NO_OPTIMIZATION
 
+// When inputs and outputs are multiples of bytes
+// and the requested endian matches that of the host,
+// use the non-portable -- and hopefully-faster -- implementation instead
+
 #ifdef BOOST_LITTLE_ENDIAN
-template <int InputBits, int OutputBits, bool Ex, bool Im>
+template <int InputBits, int OutputBits>
+struct packer<stream_endian::little_bit,
+ InputBits, OutputBits, true>
+ : real_packer<stream_endian::host_byte,
+ InputBits, OutputBits> {};
+template <int InputBits, int OutputBits>
 struct packer<stream_endian::little_byte_big_bit,
- InputBits, OutputBits,
- Ex, Im, true, true>
- : packer<stream_endian::host_byte,
- InputBits, OutputBits,
- Ex, Im, true, true> {};
-template <int InputBits, int OutputBits, bool Ex, bool Im>
+ InputBits, OutputBits, true>
+ : real_packer<stream_endian::host_byte,
+ InputBits, OutputBits> {};
+template <int InputBits, int OutputBits>
 struct packer<stream_endian::little_byte_little_bit,
- InputBits, OutputBits,
- Ex, Im, true, true>
- : packer<stream_endian::host_byte,
- InputBits, OutputBits,
- Ex, Im, true, true> {};
+ InputBits, OutputBits, true>
+ : real_packer<stream_endian::host_byte,
+ InputBits, OutputBits> {};
 #endif
 
 #ifdef BOOST_BIG_ENDIAN
-template <int InputBits, int OutputBits, bool Ex, bool Im>
+template <int InputBits, int OutputBits>
+struct packer<stream_endian::big_bit,
+ InputBits, OutputBits, true>
+ : real_packer<stream_endian::host_byte,
+ InputBits, OutputBits> {};
+template <int InputBits, int OutputBits>
 struct packer<stream_endian::big_byte_big_bit,
- InputBits, OutputBits,
- Ex, Im, true, true>
- : packer<stream_endian::host_byte,
- InputBits, OutputBits,
- Ex, Im, true, true> {};
-template <int InputBits, int OutputBits, bool Ex, bool Im>
+ InputBits, OutputBits, true>
+ : real_packer<stream_endian::host_byte,
+ InputBits, OutputBits> {};
+template <int InputBits, int OutputBits>
 struct packer<stream_endian::big_byte_little_bit,
- InputBits, OutputBits,
- Ex, Im, true, true>
- : packer<stream_endian::host_byte,
- InputBits, OutputBits,
- Ex, Im, true, true> {};
+ InputBits, OutputBits, true>
+ : real_packer<stream_endian::host_byte,
+ InputBits, OutputBits> {};
 #endif
 
 #endif


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk