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
| 1721 | // - We don't do 'current += 2; continue;' after handling ### to keep the code smaller/faster (measured ~10% diff in Debug build) |
| 1722 | // FIXME-OPT: Replace with e.g. FNV1a hash? CRC32 pretty much randomly access 1KB. Need to do proper measurements. |
| 1723 | ImGuiID ImHashStr(const char* data_p, size_t data_size, ImU32 seed) |
| 1724 | { |
| 1725 | seed = ~seed; |
| 1726 | ImU32 crc = seed; |
| 1727 | const unsigned char* data = (const unsigned char*)data_p; |
| 1728 | const ImU32* crc32_lut = GCrc32LookupTable; |
| 1729 | if (data_size != 0) |
| 1730 | { |
| 1731 | while (data_size-- != 0) |
| 1732 | { |
| 1733 | unsigned char c = *data++; |
| 1734 | if (c == '#' && data_size >= 2 && data[0] == '#' && data[1] == '#') |
| 1735 | crc = seed; |
| 1736 | crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ c]; |
| 1737 | } |
| 1738 | } |
| 1739 | else |
| 1740 | { |
| 1741 | while (unsigned char c = *data++) |
| 1742 | { |
| 1743 | if (c == '#' && data[0] == '#' && data[1] == '#') |
| 1744 | crc = seed; |
| 1745 | crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ c]; |
| 1746 | } |
| 1747 | } |
| 1748 | return ~crc; |
| 1749 | } |
| 1750 | |
| 1751 | //----------------------------------------------------------------------------- |
| 1752 | // [SECTION] MISC HELPERS/UTILITIES (File functions) |
no outgoing calls
no test coverage detected