> On 10 May 2021, at 10:52, Mark Allan via Cocoa-dev 
> <cocoa-dev@lists.apple.com> wrote:
> 
> Hi,
> 
> Now that Alex has the answer to his problem, can I ask a follow-up question 
> based on this line in his initial email?
> 
>> On 9 May 2021, at 1:12 am, Alex Zavatone via Cocoa-dev 
>> <cocoa-dev@lists.apple.com> wrote:
>>       _configurationDictionary = [[NSMutableDictionary 
>> alloc]initWithDictionary:[NSDictionary 
>> dictionaryWithContentsOfFile:filePath]];
> 
> What's the benefit of having the immutable NSDictionary in the mix there?
>       _configurationDictionary = [[NSMutableDictionary alloc] 
> initWithDictionary:[NSDictionary dictionaryWithContentsOfFile:filePath]]
> 
> Is that somehow better than:
>       _configurationDictionary = [[NSMutableDictionary alloc] 
> initWithContentsOfFile:filePath]
> 
> or even:
>       _configurationDictionary = [NSMutableDictionary 
> dictionaryWithContentsOfFile:filePath]
> 
> Is any one more efficient than the other (I would've assumed the last one, 
> with there being fewer objects and messages) but I suppose it's possible the 
> compiler ends up optimising them all to be the same anyway?

It does not. The ObjC compiler is not in a position to make such optimisations. 
But worrying about optimisation on that level is pointless; you’re about to hit 
the file system which is vastly slower than an extra message send.

Most likely the OP has just gone with what reads most conveniently to them and 
hasn’t considered changing it. It would be better to do:

1. Use NSData to read data from disk, handling failure
2. Use NSPropertyListSerialization to parse the data, handling failure. An 
option can be passed to ask for the whole plist to be mutable, or if only the 
top-level dictionary/array needs to be mutable, use a method like -mutableCopy

Mike.

_______________________________________________

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

Reply via email to