It's certainly the case the ship has sailed on Substring
but if we're going to have a 32 byte value type (I don't know where I mis-remembered 100 bytes from in the previous post) representing String slices and a StringProtocol
it's interesting to meditate on what might have been given this string: "fits inside thirty characters".
With that many bytes, I'd wager the majority of substrings could have been represented inside the memory of the struct itself without having to allocate or reference count â a sort of Shortstring
if you like along the lines of the optimisation mentioned with respect to NSString. If the string slice is too long it could revert to storing a SubString-like representation referring to the original storage. You loose the ability to recover the index into the original string from the slice though one wonders how often that feature was used or known about.
It might be interesting to benchmark such a solution as a nearly ABI compatible alternative to SubString to see if it offers a performance advantage worth pursuing.
enum Shortstring: StringProtocol {
case short(length: UInt8,
bytes: (CChar, CChar, CChar, CChar, CChar,
CChar, CChar, CChar, CChar, CChar,
CChar, CChar, CChar, CChar, CChar,
CChar, CChar, CChar, CChar, CChar,
CChar, CChar, CChar, CChar, CChar,
CChar, CChar, CChar, CChar, CChar,
CChar))
case long(substring: Substring)
...
}
But, at the end of the day I'm not sure even I'm convinced.