Re: Data, enumerateBytes: separate blocks?
Re: Data, enumerateBytes: separate blocks?
- Subject: Re: Data, enumerateBytes: separate blocks?
- From: Quincey Morris <email@hidden>
- Date: Wed, 27 Dec 2017 13:50:34 -0800
On Dec 27, 2017, at 11:59 , Daryle Walker <email@hidden> 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 (email@hidden)
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:
This email sent to email@hidden
References: | |
| >Re: Data, enumerateBytes: separate blocks? (From: Daryle Walker <email@hidden>) |
| >Re: Data, enumerateBytes: separate blocks? (From: Quincey Morris <email@hidden>) |
| >Re: Data, enumerateBytes: separate blocks? (From: Daryle Walker <email@hidden>) |
| >Re: Data, enumerateBytes: separate blocks? (From: Quincey Morris <email@hidden>) |
| >Re: Data, enumerateBytes: separate blocks? (From: Daryle Walker <email@hidden>) |
| >Re: Data, enumerateBytes: separate blocks? (From: Quincey Morris <email@hidden>) |
| >Re: Data, enumerateBytes: separate blocks? (From: Daryle Walker <email@hidden>) |
| >Re: Data, enumerateBytes: separate blocks? (From: Charles Srstka <email@hidden>) |
| >Re: Data, enumerateBytes: separate blocks? (From: Quincey Morris <email@hidden>) |
| >Re: Data, enumerateBytes: separate blocks? (From: Daryle Walker <email@hidden>) |
| >Re: Data, enumerateBytes: separate blocks? (From: Quincey Morris <email@hidden>) |
| >Re: Data, enumerateBytes: separate blocks? (From: Daryle Walker <email@hidden>) |