ZyX_I avatar ZyX_I committed c859449

@frawor: Instead of resorting s:featordered.all use function that adds to sorted array

Comments (0)

Files changed (1)

plugin/frawor.vim

                     \             a:shadowdict.consargs, '')
     endif
 endfunction
-"▶1 featcomp        :: feature, feature + s:deplen → -1|0|1
-function s:FeatComp(feature1, feature2)
-    let plid1=a:feature1.plid
-    let plid2=a:feature2.plid
-    let dl1=s:deplen[plid1]
-    let dl2=s:deplen[plid2]
-    if dl1==dl2
-        if plid1 is# plid2
-            return ((a:feature1.id>a:feature2.id)?(1):(-1))
-        endif
-        return ((plid1>plid2)?(1):(-1))
-    endif
-    return ((dl1<dl2)?(1):(-1))
-endfunction
-" " 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:featordered.all → + p:_f
 function s:F.addcons(plugdict)
     let shadowdict=s:shadow[a:plugdict.id]
         return []
     endif
 endfunction
-"▶1 _unload
-function s:._unload()
-    delfunction s:FeatComp
-endfunction
 "▶1 FraworRegister
 function FraworRegister(...)
     return call(s:F.newplugin, a:000, {})
         call s:_f.throw('invkey', a:fname, a:plid, a:key)
     endif
 endfunction
+"▶1 featcomp        :: feature, feature + s:deplen → -1|0|1
+function s:F.featcomp(feature1, feature2)
+    let plid1=a:feature1.plid
+    let plid2=a:feature2.plid
+    let dl1=s:deplen[plid1]
+    let dl2=s:deplen[plid2]
+    if dl1==dl2
+        if plid1 is# plid2
+            return ((a:feature1.id>a:feature2.id)?(1):(-1))
+        endif
+        return ((plid1>plid2)?(1):(-1))
+    endif
+    return ((dl1<dl2)?(1):(-1))
+endfunction
+"▶1 biadd                      :: [a], a, cmp → + [a]
+function s:F.biadd(list, item, Cmp)
+    let llist=len(a:list)
+    let d={'cmp': a:Cmp}
+    if !llist
+        call add(a:list, a:item)
+    elseif llist==1
+        call call((d.cmp(a:list[0], a:item)>0)?('insert'):('add'),
+                    \[a:list, a:item])
+    else
+        if d.cmp(a:list[0], a:item)>0
+            call insert(a:list, a:item)
+            return
+        elseif d.cmp(a:list[-1], a:item)<0
+            call add(a:list, a:item)
+            return
+        endif
+        let lborder=0
+        let rborder=llist-1
+        let cur=(((rborder+1)/2)-1)
+        while lborder!=rborder
+            let cr=d.cmp(a:list[cur], a:item)
+            let shift=((rborder-lborder)/2)
+            if !shift
+                break
+            endif
+            let {(cr>0)?('r'):('l')}border=cur
+            let cur=lborder+shift
+        endwhile
+        call insert(a:list, a:item, rborder)
+    endif
+endfunction
 "▶1 features.newfeature.cons   :: {f}, fid, fopts → + s:features, shadowdict, …
 let s:newfeature={
             \'plid': 'plugin/frawor',
     let a:fdict[feature.name]=feature
     let s:features[feature.id]=feature
     let s:plfeatures[a:plugdict.id]=a:fdict
-    let s:featordered={'all': sort(values(s:features), function('s:FeatComp'))}
+    let s:featordered={'all': s:featordered.all}
+    call s:F.biadd(s:featordered.all, feature, s:F.featcomp)
     "▶2 Running addfeature()
     call map(((has_key(feature, 'ignoredeps'))?
                 \(values(s:pls)):
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.