• 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: Code Comments
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Code Comments


  • Subject: Re: Code Comments
  • From: James Montgomerie <email@hidden>
  • Date: Mon, 10 Sep 2012 11:04:54 +0100

On 9 Sep 2012, at 17:57, koko <email@hidden> wrote:
> On Sep 9, 2012, at 7:35 AM, Mike Abdullah wrote:
>
>> NSXMLParser supports NSInputStream directly these days; consider moving to that
>
> That is excellent but for now I must run on 10.5.8 …

Aside from the memory management issues already pointed out, there a performance improvement you can make here.  Since you know that the parser will not continue to use the data after the parse, you can avoid physically copying the buffer when you create the NSData by using NSData's initWithBytesNoCopy:... methods.  These cause the NSData to be backed by the buffer you pass in rather than copying it to a new one owned by the NSData as usual.

- (void)startMessageParse:(void*)msgStart end:(void*)msgEnd
{
    NSInteger length = msgEnd-msgStart+1;
    if(length > 0)
    {
        NSData *data = [[NSData alloc] initWithBytesNoCopy:msgStart length:length freeWhenDone:NO];
        if(data)
        {
            NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:data];
            [xmlParser setDelegate:m_xmlParserDelegate];
            [xmlParser parse];
            [xmlParser release];
            [data release];
        }
    }
    m_state = NEWMESSAGE;
}


By the way, that "length = msgEnd-msgStart+1" looks odd to me.  Your msgEnd really points to the last valid character, not one past it?

Jamie.
_______________________________________________

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: 
 >Code Comments (From: koko <email@hidden>)
 >Re: Code Comments (From: Mike Abdullah <email@hidden>)
 >Re: Code Comments (From: koko <email@hidden>)

  • Prev by Date: NSTableView & setContentMaxSize:
  • Next by Date: Re: KVO Question: How to programmatically determine if one object is observing another on a keyPath and context?
  • Previous by thread: Re: Code Comments
  • Next by thread: Strange crash while loading nib
  • Index(es):
    • Date
    • Thread