On Dec 27, 2017, at 11:59 , Daryle Walker <dary...@mac.com> wrote: > >> guard let firstBreak = index(where: { >> [MyConstants.cr, MyConstants.lf].contains($0) >> }) else { return nil }
I would be inclined to code it like this: > guard let firstBreak = index(where: { > $0 == MyConstants.cr || MyConstants.lf == $0 > }) else { return nil } It *should* be possible for the compiler to optimize your version to this, at least in a release build, but after a certain amount of complexity in the source, it might be asking too much. Since your test result showed “contains” actually being invoked, you know you have that overhead, and also I wonder if there’s some overhead in setting up the array value for every byte. > I wonder if using something like [2] *My* [2]? I dunno exactly, the difference is that it eliminates the invocation of “index(where:)” for each byte. It’s not clear whether the current (or the upcoming) Swift compiler could actually inline the method, which would make it a wash, or if the overhead is worth worrying about. My advice is, as usual, don’t go to extraordinary lengths to optimize something unless you know you have a performance problem, and breaking out of a pure Swift idiom might be a little extraordinary. _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com