]> khamidou — GitHub mirrors - electron.git/commitdiff
Make spliting paths faster.
authorCheng Zhao <zcbenz@gmail.com>
Thu, 25 Sep 2014 14:18:40 +0000 (22:18 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Thu, 25 Sep 2014 14:18:40 +0000 (22:18 +0800)
atom/common/lib/asar.coffee

index 98e30535342deed0ee35fda45da21ca55b9d844c..eed88a220e45ffd1a43bd6751c3f40adf7327285 100644 (file)
@@ -18,14 +18,11 @@ process.on 'exit', ->
 
 # Separate asar package's path from full path.
 splitPath = (p) ->
-  return [false, p] unless typeof p is 'string'
-  components = p.split path.sep
-  for c, i in components by -1
-    if path.extname(c) is '.asar'
-      asarPath = components.slice(0, i + 1).join path.sep
-      filePath = components.slice(i + 1).join path.sep
-      return [true, asarPath, filePath]
-  return [false, p]
+  return [false] if typeof p isnt 'string'
+  return [true, p, ''] if p.substr(-5) is '.asar'
+  index = p.lastIndexOf ".asar#{path.sep}"
+  return [false] if index is -1
+  [true, p.substr(0, index + 5), p.substr(index + 6)]
 
 # Convert asar archive's Stats object to fs's Stats object.
 nextInode = 0