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
| 2320 | // - We don't do 'current += 2; continue;' after handling ### to keep the code smaller/faster (measured ~10% diff in Debug build) |
| 2321 | // FIXME-OPT: Replace with e.g. FNV1a hash? CRC32 pretty much randomly access 1KB. Need to do proper measurements. |
| 2322 | ImGuiID ImHashStr(const char* data_p, size_t data_size, ImGuiID seed) |
| 2323 | { |
| 2324 | seed = ~seed; |
| 2325 | ImU32 crc = seed; |
| 2326 | const unsigned char* data = (const unsigned char*)data_p; |
| 2327 | #ifndef IMGUI_ENABLE_SSE4_2_CRC |
| 2328 | const ImU32* crc32_lut = GCrc32LookupTable; |
| 2329 | #endif |
| 2330 | if (data_size != 0) |
| 2331 | { |
| 2332 | while (data_size-- != 0) |
| 2333 | { |
| 2334 | unsigned char c = *data++; |
| 2335 | if (c == '#' && data_size >= 2 && data[0] == '#' && data[1] == '#') |
| 2336 | crc = seed; |
| 2337 | #ifndef IMGUI_ENABLE_SSE4_2_CRC |
| 2338 | crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ c]; |
| 2339 | #else |
| 2340 | crc = _mm_crc32_u8(crc, c); |
| 2341 | #endif |
| 2342 | } |
| 2343 | } |
| 2344 | else |
| 2345 | { |
| 2346 | while (unsigned char c = *data++) |
| 2347 | { |
| 2348 | if (c == '#' && data[0] == '#' && data[1] == '#') |
| 2349 | crc = seed; |
| 2350 | #ifndef IMGUI_ENABLE_SSE4_2_CRC |
| 2351 | crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ c]; |
| 2352 | #else |
| 2353 | crc = _mm_crc32_u8(crc, c); |
| 2354 | #endif |
| 2355 | } |
| 2356 | } |
| 2357 | return ~crc; |
| 2358 | } |
| 2359 | |
| 2360 | //----------------------------------------------------------------------------- |
| 2361 | // [SECTION] MISC HELPERS/UTILITIES (File functions) |
no outgoing calls
no test coverage detected