Account for seamless slices in C roc_str_len

This commit is contained in:
Richard Feldman 2023-03-18 12:44:39 -04:00
parent 75ca8816c3
commit f862540c65
No known key found for this signature in database
GPG Key ID: F1F21AA5B1D9E43B

View File

@ -186,7 +186,7 @@ size_t roc_str_len(struct RocStr str)
uint8_t last_byte = bytes[sizeof(str) - 1]; uint8_t last_byte = bytes[sizeof(str) - 1];
uint8_t last_byte_xored = last_byte ^ 0b10000000; uint8_t last_byte_xored = last_byte ^ 0b10000000;
size_t small_len = (size_t)(last_byte_xored); size_t small_len = (size_t)(last_byte_xored);
size_t big_len = str.len; size_t big_len = str.len & PTRDIFF_MAX; // Account for seamless slices
// Avoid branch misprediction costs by always // Avoid branch misprediction costs by always
// determining both small_len and big_len, // determining both small_len and big_len,