2009-09-08 1 views
1
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); 
+6

私はどれくらいのSOユーザーがこのスレッドに "StringBuilder!StringBuilder"という叫び声を出したのでしょうか? –

答えて

6

は考えてみましょう:

char *buf = [coordStr UTF8String]; 
sscanf(buf, "%f,%f", &routePoints[i].latitude, routePoints[i].longitude); 
2

[coordStr UTF8String]の返されたC文字列を使用して、手動で文字を解析することを検討します。

2

これはNSScannerが勝つだろう場合のように私には見えます。 -componentsSeparatedByStringと-substringFromIndexはともにヒープオブジェクトを作成する予定です。これはタイトなループで実行したくないものです。

2

私はちょうど私がここにジャンプし、あなたのライン[coords release]は不要で(そして間違っている)と言っていました。 GC以外の環境での問題を回避するには、これを削除する必要があります。 coordsを明示的に作成または保持していないため、リリースする必要はありません。

関連する問題