message: Refactored string_to_name(str) in name.hpp
diff: @@ -14,29 +14,28 @@ namespace eosio { namespace chain {
  return 0;
  }
  - static constexpr uint64_t string_to_name( const char* str ) {
  -
  - uint32_t len = 0;
  - while( str[len] ) ++len;
  -
  - uint64_t value = 0;
  -
  - for( uint32_t i = 0; i <= 12; ++i ) {
  - uint64_t c = 0;
  - if( i < len && i <= 12 ) c = char_to_symbol( str[i] );
  -
  - if( i < 12 ) {
  - c &= 0x1f;
  - c <<= 64-5*(i+1);
  - }
  - else {
  - c &= 0x0f;
  - }
  -
  - value |= c;
  + // Each char of the string is encoded into 5-bit chunk and left-shifted
  + // to its 5-bit slot starting with the highest slot for the first char.
  + // The 13th char, if str is long enough, is encoded into 4-bit chunk
  + // and placed in the lowest 4 bits. 64 = 12 * 5 + 4
  + static constexpr uint64_t string_to_name( const char* str )
  + {
  + uint64_t name = 0;
  + int i;
  + for (i = 0; str[i] && i < 12; ++i) {
  + // Retrieve the encoding of str[i] (see 'charmap'
  + // operator string() method, in the .cpp file) and left-shift it
  + // to the 5-bit slot corresponding to the str[i] ordinal counted
  + // counted from the top, down.
  + name |= char_to_symbol(str[i]) << (64 - 5 * (i + 1));
  }
  - return value;
  + // The for-loop encoded up to 60 high bits into uint64 'name' variable,
  + // if (strlen(str) > 12) then encode str[12] into the low (remaining)
  + // 4 bits of 'name'
  + if (i == 12)
  + name |= char_to_symbol(str[12]) & 0x0F;
  + return name;
  }
  #define N(X) eosio::chain::string_to_name(#X)
  