🐎 Test for prefix without calling path.join

Directory::relativize is called many times by the fuzzy finder
and using path.join possibly multiple times per call was consuming
much of the time take to show the fuzzy finder view.
This commit is contained in:
Kevin Sawicki
2014-01-08 17:55:08 -08:00
parent dce70b35b5
commit 371e31c786

View File

@@ -73,11 +73,11 @@ class Directory
if fullPath is @getPath()
''
else if fullPath.indexOf(path.join(@getPath(), path.sep)) is 0
else if @isPathPrefixOf(@getPath(), fullPath)
fullPath.substring(@getPath().length + 1)
else if fullPath is @getRealPathSync()
''
else if fullPath.indexOf(path.join(@getRealPathSync(), path.sep)) is 0
else if @isPathPrefixOf(@getRealPathSync(), fullPath)
fullPath.substring(@getRealPathSync().length + 1)
else
fullPath
@@ -139,3 +139,7 @@ class Directory
if @watchSubscription?
@watchSubscription.close()
@watchSubscription = null
# Private: Does given full path start with the given prefix?
isPathPrefixOf: (prefix, fullPath) ->
fullPath.indexOf(prefix) is 0 and fullPath[prefix.length] is path.sep