| 103 | // without any bounds checking. |
| 104 | |
| 105 | inline uint32_t DecodeFixed32(const char* ptr) { |
| 106 | const uint8_t* const buffer = reinterpret_cast<const uint8_t*>(ptr); |
| 107 | |
| 108 | if (port::kLittleEndian) { |
| 109 | // Fast path for little-endian CPUs. All major compilers optimize this to a |
| 110 | // single mov (x86_64) / ldr (ARM) instruction. |
| 111 | uint32_t result; |
| 112 | std::memcpy(&result, buffer, sizeof(uint32_t)); |
| 113 | return result; |
| 114 | } |
| 115 | |
| 116 | // Platform-independent code. |
| 117 | // Clang and gcc optimize this to a single mov / ldr instruction. |
| 118 | return (static_cast<uint32_t>(buffer[0])) | |
| 119 | (static_cast<uint32_t>(buffer[1]) << 8) | |
| 120 | (static_cast<uint32_t>(buffer[2]) << 16) | |
| 121 | (static_cast<uint32_t>(buffer[3]) << 24); |
| 122 | } |
| 123 | |
| 124 | inline uint64_t DecodeFixed64(const char* ptr) { |
| 125 | const uint8_t* const buffer = reinterpret_cast<const uint8_t*>(ptr); |
no outgoing calls