cmsc430 / cmsc430.github.io

CMSC 430 Design and Implementation of Programming Languages
https://cmsc430.github.io/
45 stars 33 forks source link

Array data structures should keep their lengths encoded #136

Open dvanhorn opened 1 year ago

dvanhorn commented 1 year ago

Our current layout for strings and vectors is to store their unencoded length in the first word, but there's really no good reason doing it this way it and it means you have to re-encode it when you access the length. I think this was originally done to make bounds checking simpler to understand, but it's basically the same encoded or not. Changing this would simplify the code a bit.

Arguably the same should be done for the character data in strings. We have the bits available, so using codepoints doesn't buy you anything except the work of de/re-coding.

It's technically possible to pack 3 codepoints per words (but not chars), but we don't do that.