Ported absolute and isFile to Objective-c.

This took fileFinder loading from .8 seconds to .35 seconds.
This commit is contained in:
Corey Johnson & Nathan Sobo
2012-01-03 17:50:43 -08:00
parent 982d5a4426
commit 7ba7ba2c81
2 changed files with 21 additions and 12 deletions

View File

@@ -155,6 +155,25 @@
});
}
- (BOOL)isFile:(NSString *)path {
BOOL isDir;
BOOL exists;
exists = [[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:&isDir];
return exists && !isDir;
}
- (NSString *)absolute:(NSString *)path {
path = [path stringByStandardizingPath];
if ([path characterAtIndex:0] == '/') {
return path;
}
NSString *resolvedPath = [[NSFileManager defaultManager] currentDirectoryPath];
resolvedPath = [[resolvedPath stringByAppendingPathComponent:path] stringByStandardizingPath];
return resolvedPath;
}
#pragma mark NSWindowDelegate
- (BOOL)windowShouldClose:(id)sender {
[self close];

View File

@@ -9,13 +9,7 @@ module.exports =
# Make the given path absolute by resolving it against the
# current working directory.
absolute: (path) ->
path = OSX.NSString.stringWithString(path).stringByStandardizingPath
return path if path.toString()[0] == "/"
resolvedString = OSX.NSString.stringWithString(@workingDirectory())
resolvedString = resolvedString.stringByAppendingPathComponent(path).stringByStandardizingPath
resolvedString.toString()
$atomController.absolute(path).toString()
# Return the basename of the given path. That is the path with
# any leading directory components removed. If specified, also
@@ -48,11 +42,7 @@ module.exports =
# Returns true if the file specified by path exists and is a
# regular file.
isFile: (path) ->
path = @absolute path
isDir = new jscocoa.outArgument
exists = OSX.NSFileManager.defaultManager.
fileExistsAtPath_isDirectory path, isDir
exists and not isDir.valueOf()
$atomController.isFile path
# Returns an array with all the names of files contained
# in the directory path.