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;
}
init = annotations => {
// TODO - there are several performance optimzations that are not yet ported
// across from Recogito
annotations
// Discard all annotations without a TextPositionSelector
.filter(annotation => annotation.selector('TextPositionSelector'))
.forEach(annotation => this._addAnnotation(annotation));
init = annotations => {
// Discard all annotations without a TextPositionSelector
const highlights = annotations.filter(a => a.selector('TextPositionSelector'));
// Sorting bottom to top significantly speeds things up,
// because walkTextNodes will have a lot less to walk
highlights.sort((a, b) => b.start - a.start);
highlights.forEach(this._addAnnotation);
}
_addAnnotation = annotation => {