prrrnd / atom-git-projects

List and open your local Git projects in Atom.
MIT License
37 stars 18 forks source link

speed up sort #10

Closed mark-hahn closed 9 years ago

mark-hahn commented 9 years ago

I got the 6 second load time down to 2 seconds by fixing slow sort code. I'll do a PR. This is the before and after code ...

sortBy: (array) ->
  array.sort (a, b) ->
    if atom.config.get('git-projects.sortBy') is 'Project name'
      a.title.toUpperCase() > b.title.toUpperCase()
    else if atom.config.get('git-projects.sortBy') is 'Latest modification date'
      fs.statSync(a.path)['mtime'] < fs.statSync(b.path)['mtime']
    else if atom.config.get('git-projects.sortBy') is 'Size'
      fs.statSync(a.path)['size'] < fs.statSync(b.path)['size']
sortBy: (array) ->
  sortfunc = switch atom.config.get('git-projects.sortBy')
    when 'Project name' then (a, b) -> 
      a.title.toUpperCase() > b.title.toUpperCase()
    when 'Latest modification date' then (a, b) -> 
      fs.statSync(a.path)['mtime'] < fs.statSync(b.path)['mtime']
    when 'Size' then (a, b) -> 
      fs.statSync(a.path)['size'] < fs.statSync(b.path)['size']
  array.sort sortfunc
mark-hahn commented 9 years ago

I'm done messing with this stuff for now. It works well for me. I apologize for all the rambling issue stuff and fork talk.

prrrnd commented 9 years ago

Thank you for your contribution!