r/linux • Social Justice Warrior • Sep 03 '14

I'm Matthew Garrett, kernel developer, firmware enabler and former fruitfly mangler. AMA!

482 Upvotes

381 comments sorted by

View all comments

Show parent comment

15

u/[deleted] Sep 04 '14

Null-terminated strings are slower than the alternative. A (pointer, length) representation allows slicing (including tokenizing / parsing) without allocation, avoids seeks to the end and is more friendly to SIMD operations. The same code gets reused for slices of any type, not just strings. A slice can point into any memory, including into a dynamic array or just a smaller range of another slice.