Hashing: handling of "###" operator to reset to seed within a string identifier doesn't include the "###" characters in the output hash anymore.

This has various simplifying properties.
Need a test engine update too.
+ Demo: removed misleading/unnecessary usage of ###.
This commit is contained in:
omar
2019-12-26 21:40:58 +01:00
committed by ocornut
parent 1e7d2adc29
commit fc89c61089
4 changed files with 23 additions and 9 deletions

View File

@@ -2368,11 +2368,8 @@ ImGuiID ImHashData(const void* data_p, size_t data_size, ImGuiID seed)
#endif
}
// 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 handling ### to keep the code smaller/faster (measured ~10% diff in Debug build)
// 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.
ImGuiID ImHashStr(const char* data_p, size_t data_size, ImGuiID seed)
{
@@ -2384,11 +2381,16 @@ ImGuiID ImHashStr(const char* data_p, size_t data_size, ImGuiID seed)
#endif
if (data_size != 0)
{
while (data_size-- != 0)
while (data_size-- > 0)
{
unsigned char c = *data++;
if (c == '#' && data_size >= 2 && data[0] == '#' && data[1] == '#')
{
crc = seed;
data += 2;
data_size -= 2;
continue;
}
#ifndef IMGUI_ENABLE_SSE4_2_CRC
crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ c];
#else
@@ -2401,7 +2403,11 @@ ImGuiID ImHashStr(const char* data_p, size_t data_size, ImGuiID seed)
while (unsigned char c = *data++)
{
if (c == '#' && data[0] == '#' && data[1] == '#')
{
crc = seed;
data += 2;
continue;
}
#ifndef IMGUI_ENABLE_SSE4_2_CRC
crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ c];
#else
@@ -2419,7 +2425,7 @@ const char* ImHashSkipUncontributingPrefix(const char* label)
const char* result = label;
while (unsigned char c = *label++)
if (c == '#' && label[0] == '#' && label[1] == '#')
result = label - 1;
result = label + 2;
return result;
}