Skip to content

Commit

Permalink
Speed up copy_find_path by specifying maxdepth in find
Browse files Browse the repository at this point in the history
  • Loading branch information
nisargjhaveri committed Jul 8, 2021
1 parent 357d176 commit 344ce7b
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/ios-deploy/ios-deploy.m
Original file line number Diff line number Diff line change
Expand Up @@ -268,13 +268,16 @@ CFStringRef copy_find_path(CFStringRef rootPath, CFStringRef namePattern) {
CFRelease(path);
return NULL;
}

if (CFStringFind(namePattern, CFSTR("/"), 0).location == kCFNotFound) {
cf_command = CFStringCreateWithFormat(NULL, NULL, CFSTR("find '%@' -name '%@' -maxdepth 1 2>/dev/null | sort | tail -n 1"), rootPath, namePattern);
} else {
cf_command = CFStringCreateWithFormat(NULL, NULL, CFSTR("find '%@' -path '%@/%@' 2>/dev/null | sort | tail -n 1"), rootPath, rootPath, namePattern);

CFIndex maxdepth = 1;
CFArrayRef findPathSlash = CFStringCreateArrayWithFindResults(NULL, namePattern, CFSTR("/"), CFRangeMake(0, CFStringGetLength(namePattern)), 0);
if (findPathSlash != NULL) {
maxdepth = CFArrayGetCount(findPathSlash) + 1;
CFRelease(findPathSlash);
}

cf_command = CFStringCreateWithFormat(NULL, NULL, CFSTR("find '%@' -path '%@/%@' -maxdepth %ld 2>/dev/null | sort | tail -n 1"), rootPath, rootPath, namePattern, maxdepth);

char command[1024] = { '\0' };
CFStringGetCString(cf_command, command, sizeof(command), kCFStringEncodingUTF8);
CFRelease(cf_command);
Expand Down

0 comments on commit 344ce7b

Please sign in to comment.