MCPcopy Create free account
hub / github.com/danoon2/Boxedwine / ImHashStr

Function ImHashStr

lib/imgui/imgui.cpp:1449–1475  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

1447// - We don't do 'current += 2; continue;' after handling ### to keep the code smaller/faster (measured ~10% diff in Debug build)
1448// FIXME-OPT: Replace with e.g. FNV1a hash? CRC32 pretty much randomly access 1KB. Need to do proper measurements.
1449ImU32 ImHashStr(const char* data_p, size_t data_size, ImU32 seed)
1450{
1451 seed = ~seed;
1452 ImU32 crc = seed;
1453 const unsigned char* data = (const unsigned char*)data_p;
1454 const ImU32* crc32_lut = GCrc32LookupTable;
1455 if (data_size != 0)
1456 {
1457 while (data_size-- != 0)
1458 {
1459 unsigned char c = *data++;
1460 if (c == '#' && data_size >= 2 && data[0] == '#' && data[1] == '#')
1461 crc = seed;
1462 crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ c];
1463 }
1464 }
1465 else
1466 {
1467 while (unsigned char c = *data++)
1468 {
1469 if (c == '#' && data[0] == '#' && data[1] == '#')
1470 crc = seed;
1471 crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ c];
1472 }
1473 }
1474 return ~crc;
1475}
1476
1477//-----------------------------------------------------------------------------
1478// [SECTION] MISC HELPERS/UTILITIES (File functions)

Callers 13

ImGuiWindowMethod · 0.85
GetIDMethod · 0.85
GetIDNoKeepAliveMethod · 0.85
InitializeMethod · 0.85
FindWindowByNameMethod · 0.85
GetWindowResizeIDMethod · 0.85
BeginDragDropSourceMethod · 0.85
FindSettingsHandlerMethod · 0.85
TabBarCalcTabIDMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected