Increase recalculation performance by additional caching

This commit is contained in:
Tobias Hößl 2020-06-07 11:44:07 +02:00
parent 18bc495bd8
commit bc3b8be78d
No known key found for this signature in database
GPG Key ID: 1D780C7599C2D2A2

View File

@ -377,8 +377,11 @@ export class LinenumberingService {
* @returns {LineNumberRange}
*/
public getLineNumberRange(html: string): LineNumberRange {
const cacheKey = this.djb2hash(html);
let range = this.lineNumberCache.get(cacheKey);
if (!range) {
const fragment = this.htmlToFragment(html);
const range = {
range = {
from: null,
to: null
};
@ -393,6 +396,8 @@ export class LinenumberingService {
range.to = number + 1;
}
}
}
this.lineNumberCache.put(cacheKey, range);
return range;
}
@ -482,10 +487,17 @@ export class LinenumberingService {
* @return {string[]}
*/
public splitToParagraphs(html: string): string[] {
const cacheKey = this.djb2hash(html);
let cachedParagraphs = this.lineNumberCache.get(cacheKey);
if (!cachedParagraphs) {
const fragment = this.htmlToFragment(html);
return this.splitNodeToParagraphs(fragment).map((node: Element): string => {
cachedParagraphs = this.splitNodeToParagraphs(fragment).map((node: Element): string => {
return node.outerHTML;
});
this.lineNumberCache.put(cacheKey, cachedParagraphs);
}
return cachedParagraphs;
}
/**