|
|
|
|
|
by ori_b
4570 days ago
|
|
> but rather that the cost of the short string is also added to the long string The key point is that for short strings, you're not adding it to the cost of the long string, but instead overwriting the data that you would track the long string. In other words, the memory layout you get is this: short:
[Rbasic]['s', 't', 'r', 'i', 'n', 'g', '\0']
long:
[Rbasic][ length ][ dataptr ][capa or value]
Which leads to another interesting question: How does the optimization interact with null in the middle of short strings, since only long strings have a length stored? Does Ruby check for embedded null when creating a string, and disable this optimization? |
|