55
edits
| Line 16: | Line 16: | ||
Strings are immutable, but their contents may be different. String data can be 8, 16, or 32 bits wide; A string may contain a pointer to a string buffer, which may need to be deleted or not; or the string data may immediately follow the String instance in memory (by doing a raw allocate followed by an in-place constructor call); or it can hold two String references if is the result of a concat operation. The contents may change dynamically during a flatten operation. Therefore, a String instance contains a <tt>union</tt> with a tag. | Strings are immutable, but their contents may be different. String data can be 8, 16, or 32 bits wide; A string may contain a pointer to a string buffer, which may need to be deleted or not; or the string data may immediately follow the String instance in memory (by doing a raw allocate followed by an in-place constructor call); or it can hold two String references if is the result of a concat operation. The contents may change dynamically during a flatten operation. Therefore, a String instance contains a <tt>union</tt> with a tag. | ||
=== String concatenation and flattening | === String concatenation and flattening === | ||
It would not be a good idea to create a new, flat string every time two strings are concatenated. Consider this loop: | It would not be a good idea to create a new, flat string every time two strings are concatenated. Consider this loop: | ||
var s = ""; | var s = ""; | ||
edits