File tree 1 file changed +38
-5
lines changed
1 file changed +38
-5
lines changed Original file line number Diff line number Diff line change @@ -519,14 +519,47 @@ local function bindAs(source)
519
519
if not docs then
520
520
return
521
521
end
522
- for _ , doc in ipairs (docs ) do
523
- if doc .type == ' doc.as' and doc .originalComment .start == source .finish + 2 then
524
- if doc .as then
525
- vm .setNode (source , vm .compileNode (doc .as ), true )
522
+ local ases = docs ._asCache
523
+ if not ases then
524
+ ases = {}
525
+ docs ._asCache = ases
526
+ for _ , doc in ipairs (docs ) do
527
+ if doc .type == ' doc.as' and doc .as then
528
+ ases [# ases + 1 ] = doc
526
529
end
527
- return true
530
+ end
531
+ table.sort (ases , function (a , b )
532
+ return a .start < b .start
533
+ end )
534
+ end
535
+
536
+ local max = # ases
537
+ local index
538
+ local left = 1
539
+ local right = max
540
+ for _ = 1 , 1000 do
541
+ index = left + (right - left ) // 2
542
+ if index <= left then
543
+ index = left
544
+ break
545
+ elseif index >= right then
546
+ index = right
547
+ break
548
+ end
549
+ local doc = ases [index ]
550
+ if doc .originalComment .start < source .finish + 2 then
551
+ left = index + 1
552
+ else
553
+ right = index
528
554
end
529
555
end
556
+
557
+ local doc = ases [index ]
558
+ if doc and doc .originalComment .start == source .finish + 2 then
559
+ vm .setNode (source , vm .compileNode (doc .as ), true )
560
+ return true
561
+ end
562
+
530
563
return false
531
564
end
532
565
You can’t perform that action at this time.
0 commit comments