mirror of
https://github.com/nicbarker/clay.git
synced 2025-04-19 04:38:01 +00:00
[Core] Add option to hash text contents to text config
This commit is contained in:
parent
5fae7a6249
commit
b9df40003f
10
clay.h
10
clay.h
@ -324,6 +324,7 @@ typedef struct {
|
|||||||
uint16_t letterSpacing;
|
uint16_t letterSpacing;
|
||||||
uint16_t lineHeight;
|
uint16_t lineHeight;
|
||||||
Clay_TextElementConfigWrapMode wrapMode;
|
Clay_TextElementConfigWrapMode wrapMode;
|
||||||
|
bool hashStringContents;
|
||||||
#ifdef CLAY_EXTEND_CONFIG_TEXT
|
#ifdef CLAY_EXTEND_CONFIG_TEXT
|
||||||
CLAY_EXTEND_CONFIG_TEXT
|
CLAY_EXTEND_CONFIG_TEXT
|
||||||
#endif
|
#endif
|
||||||
@ -987,9 +988,18 @@ uint32_t Clay__HashTextWithConfig(Clay_String *text, Clay_TextElementConfig *con
|
|||||||
uint32_t hash = 0;
|
uint32_t hash = 0;
|
||||||
uintptr_t pointerAsNumber = (uintptr_t)text->chars;
|
uintptr_t pointerAsNumber = (uintptr_t)text->chars;
|
||||||
|
|
||||||
|
if (config->hashStringContents) {
|
||||||
|
uint32_t maxLengthToHash = CLAY__MIN(text->length, 256);
|
||||||
|
for (int i = 0; i < maxLengthToHash; i++) {
|
||||||
|
hash += text->chars[i];
|
||||||
|
hash += (hash << 10);
|
||||||
|
hash ^= (hash >> 6);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
hash += pointerAsNumber;
|
hash += pointerAsNumber;
|
||||||
hash += (hash << 10);
|
hash += (hash << 10);
|
||||||
hash ^= (hash >> 6);
|
hash ^= (hash >> 6);
|
||||||
|
}
|
||||||
|
|
||||||
hash += text->length;
|
hash += text->length;
|
||||||
hash += (hash << 10);
|
hash += (hash << 10);
|
||||||
|
Loading…
Reference in New Issue
Block a user