3 ms·
hes wrong, correct string handling means processing the string serially one char at a time. carrying a size_t along with your strings like that is a waste of a
by snickerbockers 4y ago
hes wrong, correct string handling means processing the string serially one char at a time. carrying a size_t along with your strings like that is a waste of a perfectly good gpr.
- noobermin 4y agoA waste of 8 bytes?
- snickerbockers 4y agoWell technically that's implementation-defined, but yes.
- Thiez 4y ago7, since keeping track of the length allows you to skip storing the trailing 0.
- drran 4y agoIf we define `String` type as `{size_t len, size_t offset, char *data}`, then we can store up to 23 bytes directly in the struct, if we will sacrifice 1 bit of `len` field to indicate that.
- adgjlsfhk1 4y agothis was true in the 1980s, but now if you want speed, you want to use vectorized instructions, so you want to do as much work as possible 32 bytes at a time for large strings. if you don't store a length, your string processing will be an order of magnitude slower.