[swift-dev] State of String: ABI & Performance

Chris Lattner clattner at nondot.org
Thu Jan 11 16:39:04 CST 2018


Thanks Ole, that’s definitely nicer, I’ve updated my code!

Still not exactly ergonomic though :-)

-Chris

> On Jan 11, 2018, at 3:28 AM, Ole Begemann via swift-dev <swift-dev at swift.org> wrote:
> 
> 
> 
> In this particular example, you can use UInt8.init(ascii:) to make it a little nicer (no need for the charToByte function):
> 
>     func hexToInt(_ c : UInt8) -> UInt8 {
>         switch c {
>         case UInt8(ascii: "0")...UInt8(ascii: "9"):
>             return c - UInt8(ascii: "0")
>         case UInt8(ascii: "a")...UInt8(ascii: "f"):
>             return c - UInt8(ascii: "a") + 10
>         case UInt8(ascii: "A")...UInt8(ascii: "F"):
>             return c - UInt8(ascii: "A") + 10
>         default: fatalError("invalid hexadecimal character")
>         }
>     }

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-dev/attachments/20180111/1d5fd9e4/attachment.html>


More information about the swift-dev mailing list