Commits

ZyX_I committed e92402c

@frawor: More perfomance improvements: got rid of constant feature sorting. It now sorts only when feature is added

Comments (0)

Files changed (1)

plugin/frawor.vim

 let s:features={}
 let s:shadow={}
 let s:featfunckeys=['cons', 'load', 'unload', 'unloadpre', 'register']
-let s:f={}
-call map(copy(s:featfunckeys), 'extend(s:f, {v:val : {}})')
+let s:featordered={'all': []}
 let s:dependents={}
 "▶2 Messages
 if v:lang=~?'ru'
 " " Can't add s:FeatComp to _functions because it is required for unloadplugin 
 " " to  work and thus should not be removed by unloadpre event
 " let function('s:FeatComp')=function('s:FeatComp')
-"▶1 addcons         :: plugdict + s:f.cons → + p:_f
+"▶1 addcons         :: plugdict + s:featordered.all → + p:_f
 function s:F.addcons(plugdict)
     let shadowdict=s:shadow[a:plugdict.id]
-    for feature in sort(filter(values(s:f.cons),
-                \              'has_key(a:plugdict.dependencies, v:val.plid)'),
-                \       function('s:FeatComp'))
+    for feature in filter(copy(s:featordered.all),
+                \         'has_key(v:val, "cons") && '.
+                \         'has_key(a:plugdict.dependencies, v:val.plid)')
         let a:plugdict.g._f[feature.name]=s:F.createcons(a:plugdict, shadowdict,
                     \                                    feature)
     endfor
 endfunction
-"▶1 getfeatures     :: plugdict, {: feature} → [feature]
-function s:F.getfeatures(plugdict, featuresdict)
-    return sort(filter(values(a:featuresdict),
-                \      'has_key(a:plugdict.dependencies, v:val.plid) ||'.
-                \      'has_key(v:val, "ignoredeps")'),
-                \function('s:FeatComp'))
+"▶1 getfeatures     :: plugdict, key → [feature]
+function s:F.getfeatures(plugdict, key)
+    if !has_key(s:featordered, a:key)
+        let s:featordered[a:key]=filter(copy(s:featordered.all),
+                    \                   'has_key(v:val, "'.a:key.'")')
+    endif
+    return filter(copy(s:featordered[a:key]),
+                \ 'has_key(a:plugdict.dependencies, v:val.plid) ||'.
+                \ 'has_key(v:val, "ignoredeps")')
 endfunction
-"▶1 runfeatures     :: plugdict, fkey + shadowdict, +s:f → plugdict + shadowdict
+"▶1 runfeatures     :: plugdict, fkey + shadowdict, + → plugdict + shadowdict
 function s:F.runfeatures(plugdict, key)
     let fdicts=s:shadow[a:plugdict.id].features
     let fnames={}
-    for feature in filter(s:F.getfeatures(a:plugdict, s:f[a:key]),
+    for feature in filter(s:F.getfeatures(a:plugdict, a:key),
                 \         '!has_key(fnames, v:val.name)')
         let fnames[feature.name]=feature
         call call(feature[a:key], [a:plugdict, fdicts[feature.name]], {})
 "▶1 initfeatures    :: plugdict + shadowdict → + shadowdict
 function s:F.initfeatures(plugdict)
     let fdicts=s:shadow[a:plugdict.id].features
-    for feature in filter(s:F.getfeatures(a:plugdict, s:features),
+    for feature in filter(s:F.getfeatures(a:plugdict, 'all'),
                 \         '!has_key(fdicts, v:val.name)')
         let fdict={}
         let fdicts[feature.name]=fdict
     let dl1=s:deplen[plid1]
     let dl2=s:deplen[plid2]
     if dl1==dl2
-        if plid1 is# plid2
-            return ((a:plugdict1.id>a:plugdict2.id)?(1):(-1))
-        endif
         return ((plid1>plid2)?(1):(-1))
     endif
     return ((dl1<dl2)?(1):(-1))
             endfor
             call s:F.updatedeplen(plugdict)
             "▶2 Running features
-            for feature in s:F.getfeatures(plugdict, s:features)
+            for feature in s:F.getfeatures(plugdict, 'all')
                 call s:F.addfeature(plugdict, feature, 1)
             endfor
             "▲2
             call s:F.isfunc(a:fopts[key], key, feature.name, feature.plid)
         endif
         let feature[key]=a:fopts[key]
-        let s:f[key][feature.id]=feature
         let addedsomething=1
     endfor
     "▶3 Must have added something
             call s:_f.throw('initndct', feature.name, a:plugdict.id)
         endif
         let feature.init=a:fopts.init
-        let s:f.register[feature.id]=feature
     endif
     "▲2
     let a:fdict[feature.name]=feature
     let s:features[feature.id]=feature
+    let s:featordered={'all': sort(values(s:features), function('s:FeatComp'))}
     "▶2 Running addfeature()
     call map(((has_key(feature, 'ignoredeps'))?
                 \(values(s:pls)):
                 \   ([]))),
                 \'s:F.addfeature(v:val, feature)')
 endfunction
-"▶1 features.newfeature.unload :: {f} → + s:features, shadowdict, s:f
+"▶1 features.newfeature.unload :: {f} → + s:features, shadowdict
 function s:newfeature.unload(plugdict, fdict)
+    if !empty(a:fdict)
+        let s:featordered={'all': s:featordered.all}
+    endif
     for feature in values(a:fdict)
         if has_key(feature, 'ignoredeps')
             for shadowdict in values(s:shadow)
             endfor
         endif
         unlet s:features[feature.id]
-        for featdict in filter(values(s:f), 'has_key(v:val, feature.id)')
-            unlet featdict[feature.id]
-        endfor
+        call filter(s:featordered.all, 'v:val isnot feature')
     endfor
 endfunction
 let s:features[s:newfeature.id]=s:newfeature
-let s:f.cons[s:newfeature.id]=s:newfeature
-let s:f.load[s:newfeature.id]=s:newfeature
-let s:f.unload[s:newfeature.id]=s:newfeature
+let s:featordered.all+=[s:newfeature]
 "▶1 Plugin registration
 call s:F.newplugin([0, 0], s:Eval('+matchstr(expand("<sfile>"), ''\d\+'')'),
             \      expand('<sfile>:p'), {}, 1, s:)
 endfunction
 call s:_f.newfeature('throw', {'cons': s:F.throw})
 "▶1
-call frawor#Lockvar(s:, 'dependents,features,f,loading,shadow,pls,'.
+call frawor#Lockvar(s:, 'dependents,features,featordered,loading,shadow,pls,'.
             \           'rtpcache,dircache,deplen')
 lockvar 1 f
 " vim: fmr=▶,▲ sw=4 ts=4 sts=4 et tw=80
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.