TextEdit & Highlighting: performance improvements & changes to architecture
I ran pprof to find what was causing stuttering, and found it to be the getTabCountInLineAtCol function in TextEdit, because it was iterating many bytes of the buffer, for each rune rendered. Replaced it with a more optimal system. Also changed the architecture of the highlighting system to use a single RegexpRange structure for all regular expressions. This allows for optimizations and multiline matches in the future.
This commit is contained in:
@@ -96,7 +96,11 @@ func (b *RopeBuffer) Line(line int) []byte {
|
||||
// inclusive bounds. The returned value may or may not be a copy of the data,
|
||||
// so do not write to it.
|
||||
func (b *RopeBuffer) Slice(startLine, startCol, endLine, endCol int) []byte {
|
||||
return (*rope.Node)(b).Slice(b.pos(startLine, startCol), b.pos(endLine, endCol)+1)
|
||||
endPos := b.pos(endLine, endCol)+1
|
||||
if length := (*rope.Node)(b).Len(); endPos >= length {
|
||||
endPos = length-1
|
||||
}
|
||||
return (*rope.Node)(b).Slice(b.pos(startLine, startCol), endPos)
|
||||
}
|
||||
|
||||
// Bytes returns all of the bytes in the buffer. This function is very likely
|
||||
|
Reference in New Issue
Block a user