Zero-terminated string hash, with support for ### to reset back to seed value We support a syntax of "label###id" where only "###id" is included in the hash, and only "label" gets displayed. Because this syntax is rarely used we are optimizing for the common case. - If we reach ### in the string we discard the hash so far and reset to the seed. - We don't do 'current += 2; continue;' after handlin
| 1854 | // - We don't do 'current += 2; continue;' after handling ### to keep the code smaller/faster (measured ~10% diff in Debug build) |
| 1855 | // FIXME-OPT: Replace with e.g. FNV1a hash? CRC32 pretty much randomly access 1KB. Need to do proper measurements. |
| 1856 | ImGuiID ImHashStr(const char* data_p, size_t data_size, ImU32 seed) |
| 1857 | { |
| 1858 | seed = ~seed; |
| 1859 | ImU32 crc = seed; |
| 1860 | const unsigned char* data = (const unsigned char*)data_p; |
| 1861 | const ImU32* crc32_lut = GCrc32LookupTable; |
| 1862 | if (data_size != 0) |
| 1863 | { |
| 1864 | while (data_size-- != 0) |
| 1865 | { |
| 1866 | unsigned char c = *data++; |
| 1867 | if (c == '#' && data_size >= 2 && data[0] == '#' && data[1] == '#') |
| 1868 | crc = seed; |
| 1869 | crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ c]; |
| 1870 | } |
| 1871 | } |
| 1872 | else |
| 1873 | { |
| 1874 | while (unsigned char c = *data++) |
| 1875 | { |
| 1876 | if (c == '#' && data[0] == '#' && data[1] == '#') |
| 1877 | crc = seed; |
| 1878 | crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ c]; |
| 1879 | } |
| 1880 | } |
| 1881 | return ~crc; |
| 1882 | } |
| 1883 | |
| 1884 | //----------------------------------------------------------------------------- |
| 1885 | // [SECTION] MISC HELPERS/UTILITIES (File functions) |
no outgoing calls
no test coverage detected