Skip to content
This repository was archived by the owner on May 5, 2021. It is now read-only.

Commit 6e3a981

Browse files
committed
perf for attributes + instanceof
1 parent f52f0f8 commit 6e3a981

File tree

48 files changed

+221
-105
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+221
-105
lines changed

packages/core/src/VRange.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ export class VRange {
240240
} else if (position === RelativePosition.AFTER) {
241241
reference = reference.lastLeaf();
242242
}
243-
if (reference.is(ContainerNode) && !reference.hasChildren()) {
243+
if (reference instanceof ContainerNode && !reference.hasChildren()) {
244244
reference.prepend(this.start);
245245
} else if (position === RelativePosition.AFTER && reference !== this.end) {
246246
// We check that `reference` isn't `this.end` to avoid a backward
@@ -266,7 +266,7 @@ export class VRange {
266266
} else if (position === RelativePosition.AFTER) {
267267
reference = reference.lastLeaf();
268268
}
269-
if (reference.is(ContainerNode) && !reference.hasChildren()) {
269+
if (reference instanceof ContainerNode && !reference.hasChildren()) {
270270
reference.append(this.end);
271271
} else if (position === RelativePosition.BEFORE && reference !== this.start) {
272272
// We check that `reference` isn't `this.start` to avoid a backward
@@ -366,7 +366,7 @@ export class VRange {
366366
empty(): void {
367367
const removableNodes = this.selectedNodes(node => {
368368
// TODO: Replace Table check with complex table selection support.
369-
return this.mode.is(node, RuleProperty.EDITABLE) && !node.is(TableCellNode);
369+
return this.mode.is(node, RuleProperty.EDITABLE) && !(node instanceof TableCellNode);
370370
});
371371
// Remove selected nodes without touching the start range's ancestors.
372372
const startAncestors = this.start.ancestors();

packages/plugin-blockquote/src/BlockquoteXmlDomParser.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ export class BlockquoteXmlDomParser extends AbstractParser<Node> {
1313

1414
async parse(item: Element): Promise<BlockquoteNode[]> {
1515
const blockquote = new BlockquoteNode();
16-
blockquote.modifiers.append(this.engine.parseAttributes(item));
16+
const attributes = this.engine.parseAttributes(item);
17+
if (attributes.length) {
18+
blockquote.modifiers.append(attributes);
19+
}
1720
const nodes = await this.engine.parse(...item.childNodes);
1821
blockquote.append(...nodes);
1922
return [blockquote];

packages/plugin-bold/src/BoldXmlDomParser.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ export class BoldXmlDomParser extends FormatXmlDomParser {
1515
*/
1616
async parse(item: Element): Promise<VNode[]> {
1717
const bold = new BoldFormat(nodeName(item) as 'B' | 'STRONG');
18-
bold.modifiers.append(this.engine.parseAttributes(item));
18+
const attributes = this.engine.parseAttributes(item);
19+
if (attributes.length) {
20+
bold.modifiers.append(attributes);
21+
}
1922
const children = await this.engine.parse(...item.childNodes);
2023
this.applyFormat(bold, children);
2124

packages/plugin-char/src/CharDomObjectRenderer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ export class CharDomObjectRenderer extends NodeRenderer<DomObject> {
4343
// Render block edge spaces as non-breakable space (otherwise browsers
4444
// won't render them).
4545
const previous = charNodes[0].previousSibling();
46-
if (!previous || !previous.is(InlineNode)) {
46+
if (!previous || !(previous instanceof InlineNode)) {
4747
texts[0] = texts[0].replace(/^ /g, '\u00A0');
4848
}
4949
const next = charNodes[charNodes.length - 1].nextSibling();
50-
if (!next || !next.is(InlineNode)) {
50+
if (!next || !(next instanceof InlineNode)) {
5151
texts[texts.length - 1] = texts[texts.length - 1].replace(/^ /g, '\u00A0');
5252
}
5353
const textObject = { text: texts.join('') };

packages/plugin-color/src/Color.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export class Color<T extends ColorConfig = ColorConfig> extends JWPlugin<T> {
109109
// Uncolor the children and their formats as well.
110110
for (const child of node.children()) {
111111
child.modifiers.find(Attributes)?.style.remove(this.styleName);
112-
if (child.is(InlineNode)) {
112+
if (child instanceof InlineNode) {
113113
for (const format of child.modifiers.filter(Format)) {
114114
format.modifiers.find(Attributes)?.style.remove(this.styleName);
115115
}

packages/plugin-devtools/src/components/InfoComponent.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ export class InfoComponent extends OwlComponent<{}> {
5050
propRepr(vNode: VNode, propName: string): string {
5151
let prop = vNode[propName];
5252
if (propName === 'atomic') {
53-
if (vNode.is(AtomicNode)) {
53+
if (vNode instanceof AtomicNode) {
5454
return 'true';
55-
} else if (vNode.is(ContainerNode)) {
55+
} else if (vNode instanceof ContainerNode) {
5656
return 'false';
5757
} else {
5858
return '?';

packages/plugin-devtools/src/components/TreeComponent.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,10 @@ export class TreeComponent extends OwlComponent<NodeProps> {
126126
* @param node
127127
*/
128128
isFormat(node: VNode, formatName: string): boolean {
129-
return node.is(InlineNode) && !!node.modifiers.find(format => format.name === formatName);
129+
return (
130+
node instanceof InlineNode &&
131+
!!node.modifiers.find(format => format.name === formatName)
132+
);
130133
}
131134

132135
//--------------------------------------------------------------------------

packages/plugin-divider/src/DividerXmlDomParser.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ export class DividerXmlDomParser extends AbstractParser<Node> {
1313

1414
async parse(item: Element): Promise<DividerNode[]> {
1515
const divider = new DividerNode();
16-
divider.modifiers.append(this.engine.parseAttributes(item));
16+
const attributes = this.engine.parseAttributes(item);
17+
if (attributes.length) {
18+
divider.modifiers.append(attributes);
19+
}
1720

1821
const nodes = await this.engine.parse(...item.childNodes);
1922
divider.append(...nodes);

packages/plugin-heading/src/HeadingXmlDomParser.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ export class HeadingXmlDomParser extends AbstractParser<Node> {
1515

1616
async parse(item: Element): Promise<HeadingNode[]> {
1717
const heading = new HeadingNode({ level: parseInt(nodeName(item)[1], 10) });
18-
heading.modifiers.append(this.engine.parseAttributes(item));
18+
const attributes = this.engine.parseAttributes(item);
19+
if (attributes.length) {
20+
heading.modifiers.append(attributes);
21+
}
1922
const nodes = await this.engine.parse(...item.childNodes);
2023
heading.append(...nodes);
2124
return [heading];

packages/plugin-iframe/src/IframeDomObjectRenderer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export class IframeDomObjectRenderer extends NodeRenderer<DomObject> {
2020
tag: 'JW-IFRAME',
2121
shadowRoot: true,
2222
children: iframeNode.childVNodes.filter(
23-
child => child.tangible || child.is(MetadataNode),
23+
child => child.tangible || child instanceof MetadataNode,
2424
),
2525
attach: (wrap: HTMLElement): void => {
2626
if (wrap.parentElement instanceof HTMLIFrameElement) {

0 commit comments

Comments
 (0)