MCPcopy Create free account
hub / github.com/cinder/Cinder / ImHashStr

Function ImHashStr

src/imgui/imgui.cpp:2352–2388  ·  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

2350// - We don't do 'current += 2; continue;' after handling ### to keep the code smaller/faster (measured ~10% diff in Debug build)
2351// FIXME-OPT: Replace with e.g. FNV1a hash? CRC32 pretty much randomly access 1KB. Need to do proper measurements.
2352ImGuiID ImHashStr(const char* data_p, size_t data_size, ImGuiID seed)
2353{
2354 seed = ~seed;
2355 ImU32 crc = seed;
2356 const unsigned char* data = (const unsigned char*)data_p;
2357#ifndef IMGUI_ENABLE_SSE4_2_CRC
2358 const ImU32* crc32_lut = GCrc32LookupTable;
2359#endif
2360 if (data_size != 0)
2361 {
2362 while (data_size-- != 0)
2363 {
2364 unsigned char c = *data++;
2365 if (c == '#' && data_size >= 2 && data[0] == '#' && data[1] == '#')
2366 crc = seed;
2367#ifndef IMGUI_ENABLE_SSE4_2_CRC
2368 crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ c];
2369#else
2370 crc = _mm_crc32_u8(crc, c);
2371#endif
2372 }
2373 }
2374 else
2375 {
2376 while (unsigned char c = *data++)
2377 {
2378 if (c == '#' && data[0] == '#' && data[1] == '#')
2379 crc = seed;
2380#ifndef IMGUI_ENABLE_SSE4_2_CRC
2381 crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ c];
2382#else
2383 crc = _mm_crc32_u8(crc, c);
2384#endif
2385 }
2386 }
2387 return ~crc;
2388}
2389
2390// Skip to the "###" marker if any. We don't skip past to match the behavior of GetID()
2391// FIXME-OPT: This is not designed to be optimal. Use with care.

Callers 15

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

Calls

no outgoing calls

Tested by

no test coverage detected