| 1011 | namespace ada::checkers { |
| 1012 | |
| 1013 | constexpr bool has_hex_prefix_unsafe(std::string_view input) { |
| 1014 | // This is actually efficient code, see has_hex_prefix for the assembly. |
| 1015 | constexpr bool is_little_endian = std::endian::native == std::endian::little; |
| 1016 | constexpr uint16_t word0x = 0x7830; |
| 1017 | uint16_t two_first_bytes = |
| 1018 | static_cast<uint16_t>(input[0]) | |
| 1019 | static_cast<uint16_t>((static_cast<uint16_t>(input[1]) << 8)); |
| 1020 | if constexpr (is_little_endian) { |
| 1021 | two_first_bytes |= 0x2000; |
| 1022 | } else { |
| 1023 | two_first_bytes |= 0x020; |
| 1024 | } |
| 1025 | return two_first_bytes == word0x; |
| 1026 | } |
| 1027 | |
| 1028 | constexpr bool has_hex_prefix(std::string_view input) { |
| 1029 | return input.size() >= 2 && has_hex_prefix_unsafe(input); |