On 9 Sep 2012, at 17:57, koko <k...@highrolls.net> 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 (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