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
| 1506 | // - We don't do 'current += 2; continue;' after handling ### to keep the code smaller/faster (measured ~10% diff in Debug build) |
| 1507 | // FIXME-OPT: Replace with e.g. FNV1a hash? CRC32 pretty much randomly access 1KB. Need to do proper measurements. |
| 1508 | ImGuiID ImHashStr(const char* data_p, size_t data_size, ImU32 seed) |
| 1509 | { |
| 1510 | seed = ~seed; |
| 1511 | ImU32 crc = seed; |
| 1512 | const unsigned char* data = (const unsigned char*)data_p; |
| 1513 | const ImU32* crc32_lut = GCrc32LookupTable; |
| 1514 | if (data_size != 0) |
| 1515 | { |
| 1516 | while (data_size-- != 0) |
| 1517 | { |
| 1518 | unsigned char c = *data++; |
| 1519 | if (c == '#' && data_size >= 2 && data[0] == '#' && data[1] == '#') |
| 1520 | crc = seed; |
| 1521 | crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ c]; |
| 1522 | } |
| 1523 | } |
| 1524 | else |
| 1525 | { |
| 1526 | while (unsigned char c = *data++) |
| 1527 | { |
| 1528 | if (c == '#' && data[0] == '#' && data[1] == '#') |
| 1529 | crc = seed; |
| 1530 | crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ c]; |
| 1531 | } |
| 1532 | } |
| 1533 | return ~crc; |
| 1534 | } |
| 1535 | |
| 1536 | //----------------------------------------------------------------------------- |
| 1537 | // [SECTION] MISC HELPERS/UTILITIES (File functions) |
no outgoing calls
no test coverage detected