MCPcopy Create free account
hub / github.com/PCSX2/pcsx2 / ImHashStr

Function ImHashStr

3rdparty/imgui/src/imgui.cpp:2460–2505  ·  view source on GitHub ↗

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.

Source from the content-addressed store, hash-verified

2458// e.g. "label###id" outputs the same hash as "id" (and "label" is generally displayed by the UI functions)
2459// FIXME-OPT: Replace with e.g. FNV1a hash? CRC32 pretty much randomly access 1KB. Need to do proper measurements.
2460ImGuiID ImHashStr(const char* data_p, size_t data_size, ImGuiID seed)
2461{
2462 seed = ~seed;
2463 ImU32 crc = seed;
2464 const unsigned char* data = (const unsigned char*)data_p;
2465#ifndef IMGUI_ENABLE_SSE4_2_CRC
2466 const ImU32* crc32_lut = GCrc32LookupTable;
2467#endif
2468 if (data_size != 0)
2469 {
2470 while (data_size-- > 0)
2471 {
2472 unsigned char c = *data++;
2473 if (c == '#' && data_size >= 2 && data[0] == '#' && data[1] == '#')
2474 {
2475 crc = seed;
2476 data += 2;
2477 data_size -= 2;
2478 continue;
2479 }
2480#ifndef IMGUI_ENABLE_SSE4_2_CRC
2481 crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ c];
2482#else
2483 crc = _mm_crc32_u8(crc, c);
2484#endif
2485 }
2486 }
2487 else
2488 {
2489 while (unsigned char c = *data++)
2490 {
2491 if (c == '#' && data[0] == '#' && data[1] == '#')
2492 {
2493 crc = seed;
2494 data += 2;
2495 continue;
2496 }
2497#ifndef IMGUI_ENABLE_SSE4_2_CRC
2498 crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ c];
2499#else
2500 crc = _mm_crc32_u8(crc, c);
2501#endif
2502 }
2503 }
2504 return ~crc;
2505}
2506
2507// Skip to the "###" marker if any. We don't skip past to match the behavior of GetID()
2508// FIXME-OPT: This is not designed to be optimal. Use with care.

Callers 15

TableOpenContextMenuMethod · 0.85
InitializeMethod · 0.85
ImGuiWindowMethod · 0.85
NewFrameMethod · 0.85
BeginChildExMethod · 0.85
FindWindowByNameMethod · 0.85
GetIDMethod · 0.85
GetIDWithSeedMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected