Zero-terminated string hash, with support for ### to reset back to seed value. e.g. "label###id" outputs the same hash as "id" (and "label" is generally displayed by the UI functions) FIXME-OPT: Replace with e.g. FNV1a hash? CRC32 pretty much randomly access 1KB. Need to do proper measurements.
| 2437 | // e.g. "label###id" outputs the same hash as "id" (and "label" is generally displayed by the UI functions) |
| 2438 | // FIXME-OPT: Replace with e.g. FNV1a hash? CRC32 pretty much randomly access 1KB. Need to do proper measurements. |
| 2439 | ImGuiID ImHashStr(const char* data_p, size_t data_size, ImGuiID seed) |
| 2440 | { |
| 2441 | seed = ~seed; |
| 2442 | ImU32 crc = seed; |
| 2443 | const unsigned char* data = (const unsigned char*)data_p; |
| 2444 | #ifndef IMGUI_ENABLE_SSE4_2_CRC |
| 2445 | const ImU32* crc32_lut = GCrc32LookupTable; |
| 2446 | #endif |
| 2447 | if (data_size != 0) |
| 2448 | { |
| 2449 | while (data_size-- > 0) |
| 2450 | { |
| 2451 | unsigned char c = *data++; |
| 2452 | if (c == '#' && data_size >= 2 && data[0] == '#' && data[1] == '#') |
| 2453 | { |
| 2454 | crc = seed; |
| 2455 | data += 2; |
| 2456 | data_size -= 2; |
| 2457 | continue; |
| 2458 | } |
| 2459 | #ifndef IMGUI_ENABLE_SSE4_2_CRC |
| 2460 | crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ c]; |
| 2461 | #else |
| 2462 | crc = _mm_crc32_u8(crc, c); |
| 2463 | #endif |
| 2464 | } |
| 2465 | } |
| 2466 | else |
| 2467 | { |
| 2468 | while (unsigned char c = *data++) |
| 2469 | { |
| 2470 | if (c == '#' && data[0] == '#' && data[1] == '#') |
| 2471 | { |
| 2472 | crc = seed; |
| 2473 | data += 2; |
| 2474 | continue; |
| 2475 | } |
| 2476 | #ifndef IMGUI_ENABLE_SSE4_2_CRC |
| 2477 | crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ c]; |
| 2478 | #else |
| 2479 | crc = _mm_crc32_u8(crc, c); |
| 2480 | #endif |
| 2481 | } |
| 2482 | } |
| 2483 | return ~crc; |
| 2484 | } |
| 2485 | |
| 2486 | // Skip to the "###" marker if any. We don't skip past to match the behavior of GetID() |
| 2487 | // FIXME-OPT: This is not designed to be optimal. Use with care. |
no outgoing calls
no test coverage detected