• 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: NSFileWrapper - is this really so bad?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSFileWrapper - is this really so bad?


  • Subject: Re: NSFileWrapper - is this really so bad?
  • From: Nivek Research <email@hidden>
  • Date: Wed, 28 Oct 2015 06:38:48 -0400

Perhaps just a little too OCD; however, if one is sending a message like count to a large number of containers using nil (Null) can be considerably more efficient then passing an empty shared instance. The Objective-C pattern when sending a message to a nil object pointer avoids the overhead of looking up the message implementation (even if cached) and calling that implementation. Quoting from <https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/ProgrammingWithObjectiveC.pdf>:

A nil value is the safest way to initialize an object pointer if you don’t have another value to use, because it’s perfectly acceptable in Objective-C to send a message to nil. If you do send a message to nil, obviously nothing happens.

Note: If you expect a return value from a message sent to nil,the return value will be nil for object return types, 0 for numeric types, and NO for BOOL types. Returned structures have all members initialized to zero.
—kevin


> On Oct 28, 2015, at 12:59 AM,Charles Srstka <email@hidden> wrote:
>
>> On Oct 27, 2015, at 7:08 PM, Graham Cox <email@hidden> wrote:
>>
>>> On 28 Oct 2015, at 10:53 AM, Alex Kac <email@hidden <mailto:email@hidden>> wrote:
>>>
>>> Have you tried simply passing in a blank dictionary? Is that OK?
>>
>>
>> Yes, that works OK. It’s at least a simple way to shut the warning up, though strikes me as unnecessary and inefficient, FWIW.
>
> It’s not that inefficient, given that an immutable empty array or dictionary is just going to end up being a shared instance anyway, rather than actually allocating and deallocating an object. The only costs should be asking the container if it’s empty, and the usual ARC retain/release stuff.


_______________________________________________

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


  • Prev by Date: Re: Smooth adjustScroll of NSScrollView
  • Next by Date: Re: How to completely destroy/close a Window
  • Previous by thread: Re: NSFileWrapper - is this really so bad?
  • Next by thread: mysterious behavior of system font metrics
  • Index(es):
    • Date
    • Thread