Hi,
I am currently writing an XML parser that parses a lot of data, with a lot of different nodes (the XML isn't designed by me, and I have no control over the content...)
Anyway, it currently takes an unacceptably long time to download and read in (about 13 seconds) and so I'm looking for ways to increase the efficiency of the read.
I've written a function to create hash values, so that the program no longer has to do a lot of string comparison (just NSUInteger comparison), but this still isn't reducing the complexity of the read in...
So I thought maybe I could create an array of IMPs so that, I could then go something like:
for(int i = 0; i < [hashValues count]; i ++)
{
if(currHash == [[hashValues objectAtIndex:i] unsignedIntValue])
{
[impArray objectAtIndex:i];
}
}
Or something like that.
The only problem is that I don't know how to actually make the call to the IMP function?
I've read that I perform the selector that an IMP defines by going
IMP tImp = [impArray objectAtIndex:i];
tImp(self, @selector(methodName));
But, if I need to know the name of the selector anyway, what's the point?
Can anybody help me out with what I want to do? Or even just some more ways to increase the efficiency of the parser...
Here are some excerpts from my NSXMLParser Delegate: From didStartElement
if([elementName isEqualToString:@"playingFilmData"])
{
appDelegate.arrPlayingFilms = [[NSMutableArray alloc] init];
appDelegate.arrSessionTimes_ByFilm = [[NSMutableArray alloc] init];
appDelegate.arrSessionTimes_ByCinema = [[NSMutableArray alloc] init];
[self releaseData];
return;
}
else if([elementName isEqualToString:@"film_sessions"])
{
aFilm.arrSessions = [[NSMutableArray alloc] init];
[self releaseData];
return;
}
else if([elementName isEqualToString:@"session"])
{
aSession = [[ATM_SessionObject alloc] init];
aSession.session_filmID = aFilm.film_id;
[self releaseData];
return;
}
else if([elementName isEqualToString:@"sess"])
{
aFilm.arrSessions = [[NSMutableArray alloc] init];
[self releaseData];
return;
}
else if([elementName isEqualToString:@"cin"])
{
cinID = [attributeDict objectForKey:@"id"];
[self releaseData];
return;
}
else if([elementName isEqualToString:@"s"])
{
aSession = [[ATM_SessionObject alloc] init];
aSession.session_filmID = aFilm.film_id;
aSession.session_cinemaID = cinID;
[self releaseData];
return;
}
else if([elementName isEqualToString:@"flm"])
{
aFilm = [[ATM_FilmObject alloc] init];
aFilm.film_id = [attributeDict objectForKey:@"id"];
aFilm.film_epNum = 0;
[self releaseData];
return;
}
[self releaseData];
From didEndElement
/*
*0 = nowShowing_lastUpdate
*1 = s
*2 = tit
*3 = des
*4 = rate
*5 = dir
*6 = act
*7 = rel
*8 = flm
*/
NSUInteger numHash = [appDelegate murmerHashKey:elementName WithLegth:[elementName length] AndSeed:42];
if(currentElementValue)
{
if(numHash == [[hashValues objectAtIndex:0] unsignedIntValue])
{
appDelegate.strNowShowingUpdate = currentElementValue;
self releaseData];
return;
}
else if(numHash == [[hashValues objectAtIndex:1] unsignedIntValue])
{
[aFilm.arrSessions addObject:aSession];
[appDelegate.arrSessionTimes_ByFilm addObject:aSession];
[aSession release];
aSession = nil;
}
else if(numHash == [[hashValues objectAtIndex:2] unsignedIntValue])
{
[aFilm setValue:currentElementValue forKey:@"film_title"];
[self releaseData];
return;
}
else if(numHash == [[hashValues objectAtIndex:3] unsignedIntValue])
{
[aFilm setValue:currentElementValue forKey:@"film_description"];
[self releaseData];
return;
}
else if(numHash == [[hashValues objectAtIndex:4] unsignedIntValue])
{
[aFilm setValue:currentElementValue forKey:@"film_rating"];
[self releaseData];
return;
}
else if(numHash == [[hashValues objectAtIndex:5] unsignedIntValue])
{
[aFilm setValue:currentElementValue forKey:@"film_directors"];
[self releaseData];
return;
}
else if(numHash == [[hashValues objectAtIndex:6] unsignedIntValue])
{
[aFilm setValue:currentElementValue forKey:@"film_actors"];
[self releaseData];
return;
}
}
if(numHash == [[hashValues objectAtIndex:8] unsignedIntValue])
{
[appDelegate.arrPlayingFilms addObject:aFilm];
[aFilm release];
aFilm = nil;
[self releaseData];
return;
}
[self releaseData];
I hope this helps shed some more light on what I'm doing wrong. Like I said, I'm new to this area of programming (and really, I'm actually a mathematician, not a programmer by training...), so I'm really super enthusiastic to learn not what to do!!