| 78 | } |
| 79 | |
| 80 | inline void EncodeFixed64(char* dst, uint64_t value) { |
| 81 | uint8_t* const buffer = reinterpret_cast<uint8_t*>(dst); |
| 82 | |
| 83 | if (port::kLittleEndian) { |
| 84 | // Fast path for little-endian CPUs. All major compilers optimize this to a |
| 85 | // single mov (x86_64) / str (ARM) instruction. |
| 86 | std::memcpy(buffer, &value, sizeof(uint64_t)); |
| 87 | return; |
| 88 | } |
| 89 | |
| 90 | // Platform-independent code. |
| 91 | // Currently, only gcc optimizes this to a single mov / str instruction. |
| 92 | buffer[0] = static_cast<uint8_t>(value); |
| 93 | buffer[1] = static_cast<uint8_t>(value >> 8); |
| 94 | buffer[2] = static_cast<uint8_t>(value >> 16); |
| 95 | buffer[3] = static_cast<uint8_t>(value >> 24); |
| 96 | buffer[4] = static_cast<uint8_t>(value >> 32); |
| 97 | buffer[5] = static_cast<uint8_t>(value >> 40); |
| 98 | buffer[6] = static_cast<uint8_t>(value >> 48); |
| 99 | buffer[7] = static_cast<uint8_t>(value >> 56); |
| 100 | } |
| 101 | |
| 102 | // Lower-level versions of Get... that read directly from a character buffer |
| 103 | // without any bounds checking. |
no outgoing calls
no test coverage detected