本文介绍了这个循环非常慢,我想因为我创建了很多中间字符串。如何加速?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
NSArray *splitPoints = [routeGeom componentsSeparatedByString:@"], ["];
routePoints = malloc(sizeof(CLLocationCoordinate2D) * ([splitPoints count] + 1));
int i=0;
NSArray *coords;
for (NSString* coordStr in splitPoints) {
coords = [coordStr componentsSeparatedByString:@","];
routePoints[i].latitude = [[[coords objectAtIndex:0] substringFromIndex:1]floatValue];
routePoints[i].longitude = [[coords objectAtIndex:1] floatValue];
i++;
}
[coords release];
NSLog(@"** Time to split the route geometry into structs %f", [NSDate timeIntervalSinceReferenceDate] - start);
推荐答案
请考虑:
char *buf = [coordStr UTF8String];
sscanf(buf, "%f,%f", &routePoints[i].latitude, routePoints[i].longitude);
这篇关于这个循环非常慢,我想因为我创建了很多中间字符串。如何加速?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!