@@ -1184,18 +1184,31 @@ func (b *Buffer) findMatchingBrace(braceType [2]rune, start Loc, char rune) (Loc
11841184 var i int
11851185 if char == braceType [0 ] {
11861186 for y := start .Y ; y < b .LinesNum (); y ++ {
1187- sortedGroups := b .GetSortedSyntaxGroupIndices (y )
1187+ var sortedGroups []int
1188+ sortedGroupsPopulated := false
11881189 l := []rune (string (b .LineBytes (y )))
11891190 xInit := 0
11901191 if y == start .Y {
11911192 xInit = start .X
11921193 }
11931194 for x := xInit ; x < len (l ); x ++ {
11941195 r := l [x ]
1195- if r == braceType [0 ] && ! b .isLocInStringOrComment (Loc {x , y }, sortedGroups ) {
1196- i ++
1197- } else if r == braceType [1 ] && ! b .isLocInStringOrComment (Loc {x , y }, sortedGroups ) {
1198- i --
1196+ if r == braceType [0 ] {
1197+ if ! sortedGroupsPopulated {
1198+ sortedGroups = b .GetSortedSyntaxGroupIndices (y )
1199+ sortedGroupsPopulated = true
1200+ }
1201+ if ! b .isLocInStringOrComment (Loc {x , y }, sortedGroups ) {
1202+ i ++
1203+ }
1204+ } else if r == braceType [1 ] {
1205+ if ! sortedGroupsPopulated {
1206+ sortedGroups = b .GetSortedSyntaxGroupIndices (y )
1207+ sortedGroupsPopulated = true
1208+ }
1209+ if ! b .isLocInStringOrComment (Loc {x , y }, sortedGroups ) {
1210+ i --
1211+ }
11991212 if i == 0 {
12001213 return Loc {x , y }, true
12011214 }
@@ -1204,18 +1217,31 @@ func (b *Buffer) findMatchingBrace(braceType [2]rune, start Loc, char rune) (Loc
12041217 }
12051218 } else if char == braceType [1 ] {
12061219 for y := start .Y ; y >= 0 ; y -- {
1207- sortedGroups := b .GetSortedSyntaxGroupIndices (y )
1220+ var sortedGroups []int
1221+ sortedGroupsPopulated := false
12081222 l := []rune (string (b .lines [y ].data ))
12091223 xInit := len (l ) - 1
12101224 if y == start .Y {
12111225 xInit = start .X
12121226 }
12131227 for x := xInit ; x >= 0 ; x -- {
12141228 r := l [x ]
1215- if r == braceType [1 ] && ! b .isLocInStringOrComment (Loc {x , y }, sortedGroups ){
1216- i ++
1217- } else if r == braceType [0 ] && ! b .isLocInStringOrComment (Loc {x , y }, sortedGroups ){
1218- i --
1229+ if r == braceType [1 ] {
1230+ if ! sortedGroupsPopulated {
1231+ sortedGroups = b .GetSortedSyntaxGroupIndices (y )
1232+ sortedGroupsPopulated = true
1233+ }
1234+ if ! b .isLocInStringOrComment (Loc {x , y }, sortedGroups ) {
1235+ i ++
1236+ }
1237+ } else if r == braceType [0 ]{
1238+ if ! sortedGroupsPopulated {
1239+ sortedGroups = b .GetSortedSyntaxGroupIndices (y )
1240+ sortedGroupsPopulated = true
1241+ }
1242+ if ! b .isLocInStringOrComment (Loc {x , y }, sortedGroups ) {
1243+ i --
1244+ }
12191245 if i == 0 {
12201246 return Loc {x , y }, true
12211247 }
0 commit comments