Increase recalculation performance by additional caching
This commit is contained in:
parent
18bc495bd8
commit
bc3b8be78d
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user