• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Data, enumerateBytes: separate blocks?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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>)

  • Prev by Date: Re: Data, enumerateBytes: separate blocks?
  • Previous by thread: Re: Data, enumerateBytes: separate blocks?
  • Next by thread: Pasteboards and NSSecureCoding
  • Index(es):
    • Date
    • Thread