[swift-dev] Question about size of Character type
Jordan Rose
jordan_rose at apple.com
Fri Aug 19 16:04:04 CDT 2016
We have an old Radar about this, rdar://problem/16754935 <rdar://problem/16754935>. It's probably just a case we're missing in enum layout. My guess is that it's because we don't have a whole spare bit in a RawPointer, but we should be able to pick some up either from alignment or from ABI knowledge.
Jordan
> On Aug 19, 2016, at 13:30, Ole Begemann via swift-dev <swift-dev at swift.org> wrote:
>
> The Character type is essentially defined like this [1]:
>
> struct Character {
> enum Representation {
> // A _StringBuffer whose first grapheme cluster is self.
> // NOTE: may be more than 1 Character long.
> case large(_StringBuffer._Storage)
> case small(Builtin.Int63)
> }
>
> var _representation: Representation
> }
>
> Note the type of the associated value for `case .small`, `Builtin.Int63`. Presumably, this is so that the type fits into a single word, including the single bit that is needed for the enum case.
>
> However, `MemoryLayout<Character>.size` returns 9. Given the above, I would have expected 8 bytes.
>
> Why? Is this a potential optimization that hasn't been implemented? Or am I missing something?
>
> Thanks
> Ole
>
> [1]: https://github.com/apple/swift/blob/master/stdlib/public/core/Character.swift
> _______________________________________________
> swift-dev mailing list
> swift-dev at swift.org
> https://lists.swift.org/mailman/listinfo/swift-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-dev/attachments/20160819/9143ce94/attachment.html>
More information about the swift-dev
mailing list