You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by sh...@apache.org on 2013/01/08 00:56:10 UTC
ios commit: IOS fix slow contact access due to photos temp file
generation
Updated Branches:
refs/heads/master 4d948963e -> c6a1dbe3b
IOS fix slow contact access due to photos temp file generation
"Do-while test if tmp file exists" costs a lot. Use mktemp instead to generate photo tmp file.
Before (300 contacts with pictures):
5minutes
After:
10 seconds
Project: http://git-wip-us.apache.org/repos/asf/cordova-ios/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-ios/commit/c6a1dbe3
Tree: http://git-wip-us.apache.org/repos/asf/cordova-ios/tree/c6a1dbe3
Diff: http://git-wip-us.apache.org/repos/asf/cordova-ios/diff/c6a1dbe3
Branch: refs/heads/master
Commit: c6a1dbe3bb93516e5bb1ca3567f04dc157438263
Parents: 4d94896
Author: Manu <e....@gmail.com>
Authored: Wed Dec 12 13:07:46 2012 +0100
Committer: Shazron Abdullah <sh...@apache.org>
Committed: Mon Jan 7 15:55:57 2013 -0800
----------------------------------------------------------------------
CordovaLib/Classes/CDVContact.m | 13 ++++++-------
1 files changed, 6 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/c6a1dbe3/CordovaLib/Classes/CDVContact.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVContact.m b/CordovaLib/Classes/CDVContact.m
index 9389207..469e743 100644
--- a/CordovaLib/Classes/CDVContact.m
+++ b/CordovaLib/Classes/CDVContact.m
@@ -1311,13 +1311,12 @@ static NSDictionary* org_apache_cordova_contacts_defaultFields = nil;
// get the temp directory path
NSString* docsPath = [NSTemporaryDirectory ()stringByStandardizingPath];
NSError* err = nil;
- NSFileManager* fileMgr = [[NSFileManager alloc] init];
- // generate unique file name
- NSString* filePath;
- int i = 1;
- do {
- filePath = [NSString stringWithFormat:@"%@/photo_%03d.jpg", docsPath, i++];
- } while ([fileMgr fileExistsAtPath:filePath]);
+ NSString* filePath = [NSString stringWithFormat:@"%@/photo_XXXXX", docsPath];
+ char template[filePath.length + 1];
+ strcpy(template, [filePath cStringUsingEncoding:NSASCIIStringEncoding]);
+ char* filename = mktemp(template);
+ filePath = [NSString stringWithCString:filename encoding:NSASCIIStringEncoding];
+
// save file
if ([data writeToFile:filePath options:NSAtomicWrite error:&err]) {
photos = [NSMutableArray arrayWithCapacity:1];