Performance tweak

This commit is contained in:
Rainer Simon 2020-04-05 18:02:18 +02:00
parent ddd87c12c8
commit 14dd42bad0
1 changed files with 8 additions and 7 deletions

View File

@ -11,13 +11,14 @@ export default class Highlighter {
this.formatter = formatter; this.formatter = formatter;
} }
init = annotations => { init = annotations => {
// TODO - there are several performance optimzations that are not yet ported // Discard all annotations without a TextPositionSelector
// across from Recogito const highlights = annotations.filter(a => a.selector('TextPositionSelector'));
annotations
// Discard all annotations without a TextPositionSelector // Sorting bottom to top significantly speeds things up,
.filter(annotation => annotation.selector('TextPositionSelector')) // because walkTextNodes will have a lot less to walk
.forEach(annotation => this._addAnnotation(annotation)); highlights.sort((a, b) => b.start - a.start);
highlights.forEach(this._addAnnotation);
} }
_addAnnotation = annotation => { _addAnnotation = annotation => {