Skip to content

Commit

Permalink
Merge pull request #1836 from ckeditor/i/6529
Browse files Browse the repository at this point in the history
Other: Inlined calls to parent classes in model and view `is()` checks to improve editor performance. Closes #6529.
  • Loading branch information
Reinmar authored Apr 8, 2020
2 parents f366297 + cc0633b commit 7fafc45
Show file tree
Hide file tree
Showing 29 changed files with 116 additions and 61 deletions.
2 changes: 1 addition & 1 deletion packages/ckeditor5-engine/src/model/documentfragment.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export default class DocumentFragment {
* @returns {Boolean}
*/
is( type ) {
return type == 'documentFragment' || type == 'model:documentFragment';
return type === 'documentFragment' || type === 'model:documentFragment';
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/ckeditor5-engine/src/model/documentselection.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ export default class DocumentSelection {
* @returns {Boolean}
*/
is( type ) {
return type == 'selection' ||
return type === 'selection' ||
type == 'model:selection' ||
type == 'documentSelection' ||
type == 'model:documentSelection';
Expand Down
11 changes: 6 additions & 5 deletions packages/ckeditor5-engine/src/model/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,14 @@ export default class Element extends Node {
* @returns {Boolean}
*/
is( type, name = null ) {
const cutType = type.replace( /^model:/, '' );

if ( !name ) {
return cutType == 'element' || cutType == this.name || super.is( type );
} else {
return cutType == 'element' && name == this.name;
return type === 'element' || type === 'model:element' ||
type === this.name || type === 'model:' + this.name ||
// From super.is(). This is highly utilised method and cannot call super. See ckeditor/ckeditor5#6529.
type === 'node' || type === 'model:node';
}

return name === this.name && ( type === 'element' || type === 'model:element' );
}

/**
Expand Down
4 changes: 3 additions & 1 deletion packages/ckeditor5-engine/src/model/liveposition.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ export default class LivePosition extends Position {
* @returns {Boolean}
*/
is( type ) {
return type == 'livePosition' || type == 'model:livePosition' || super.is( type );
return type === 'livePosition' || type === 'model:livePosition' ||
// From super.is(). This is highly utilised method and cannot call super. See ckeditor/ckeditor5#6529.
type == 'position' || type === 'model:position';
}

/**
Expand Down
4 changes: 3 additions & 1 deletion packages/ckeditor5-engine/src/model/liverange.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ export default class LiveRange extends Range {
* @returns {Boolean}
*/
is( type ) {
return type == 'liveRange' || type == 'model:liveRange' || super.is( type );
return type === 'liveRange' || type === 'model:liveRange' ||
// From super.is(). This is highly utilised method and cannot call super. See ckeditor/ckeditor5#6529.
type == 'range' || type === 'model:range';
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/ckeditor5-engine/src/model/markercollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ class Marker {
* @returns {Boolean}
*/
is( type ) {
return type == 'marker' || type == 'model:marker';
return type === 'marker' || type === 'model:marker';
}

/**
Expand Down
11 changes: 1 addition & 10 deletions packages/ckeditor5-engine/src/model/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import toMap from '@ckeditor/ckeditor5-utils/src/tomap';
import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
import compareArrays from '@ckeditor/ckeditor5-utils/src/comparearrays';

// To check if component is loaded more than once.
import '@ckeditor/ckeditor5-utils/src/version';

Expand Down Expand Up @@ -432,7 +431,7 @@ export default class Node {
* @returns {Boolean}
*/
is( type ) {
return type == 'node' || type == 'model:node';
return type === 'node' || type === 'model:node';
}

/**
Expand Down Expand Up @@ -500,11 +499,3 @@ export default class Node {
this._attrs.clear();
}
}

/**
* The node's parent does not contain this node.
*
* This error may be thrown from corrupted trees.
*
* @error model-node-not-found-in-parent
*/
2 changes: 1 addition & 1 deletion packages/ckeditor5-engine/src/model/position.js
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ export default class Position {
* @returns {Boolean}
*/
is( type ) {
return type == 'position' || type == 'model:position';
return type === 'position' || type === 'model:position';
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/ckeditor5-engine/src/model/range.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export default class Range {
* @returns {Boolean}
*/
is( type ) {
return type == 'range' || type == 'model:range';
return type === 'range' || type === 'model:range';
}

/**
Expand Down
16 changes: 12 additions & 4 deletions packages/ckeditor5-engine/src/model/rootelement.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,19 @@ export default class RootElement extends Element {
* @returns {Boolean}
*/
is( type, name ) {
const cutType = type.replace( 'model:', '' );
if ( !name ) {
return cutType == 'rootElement' || super.is( type );
} else {
return ( cutType == 'rootElement' && name == this.name ) || super.is( type, name );
return type === 'rootElement' || type === 'model:rootElement' ||
// From super.is(). This is highly utilised method and cannot call super. See ckeditor/ckeditor5#6529.
type === 'element' || type === 'model:element' ||
type === this.name || type === 'model:' + this.name ||
type === 'node' || type === 'model:node';
}

return name === this.name && (
type === 'rootElement' || type === 'model:rootElement' ||
// From super.is(). This is highly utilised method and cannot call super. See ckeditor/ckeditor5#6529.
type === 'element' || type === 'model:element'
);
}

/**
Expand All @@ -105,3 +112,4 @@ export default class RootElement extends Element {
// @if CK_DEBUG_ENGINE // console.log( 'ModelRootElement: ' + this );
// @if CK_DEBUG_ENGINE // }
}

2 changes: 1 addition & 1 deletion packages/ckeditor5-engine/src/model/selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ export default class Selection {
* @returns {Boolean}
*/
is( type ) {
return type == 'selection' || type == 'model:selection';
return type === 'selection' || type === 'model:selection';
}

/**
Expand Down
4 changes: 3 additions & 1 deletion packages/ckeditor5-engine/src/model/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ export default class Text extends Node {
* @returns {Boolean}
*/
is( type ) {
return type == 'text' || type == 'model:text' || super.is( type );
return type === 'text' || type === 'model:text' ||
// From super.is(). This is highly utilised method and cannot call super. See ckeditor/ckeditor5#6529.
type === 'node' || type === 'model:node';
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/ckeditor5-engine/src/model/textproxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export default class TextProxy {
* @returns {Boolean}
*/
is( type ) {
return type == 'textProxy' || type == 'model:textProxy';
return type === 'textProxy' || type === 'model:textProxy';
}

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/ckeditor5-engine/src/model/writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1360,14 +1360,14 @@ export default class Writer {
const markerRange = marker.getRange();
let isAffected = false;

if ( type == 'move' ) {
if ( type === 'move' ) {
isAffected =
positionOrRange.containsPosition( markerRange.start ) ||
positionOrRange.start.isEqual( markerRange.start ) ||
positionOrRange.containsPosition( markerRange.end ) ||
positionOrRange.end.isEqual( markerRange.end );
} else {
// if type == 'merge'.
// if type === 'merge'.
const elementBefore = positionOrRange.nodeBefore;
const elementAfter = positionOrRange.nodeAfter;

Expand Down
14 changes: 10 additions & 4 deletions packages/ckeditor5-engine/src/view/attributeelement.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,18 @@ export default class AttributeElement extends Element {
* @returns {Boolean}
*/
is( type, name = null ) {
const cutType = type && type.replace( /^view:/, '' );

if ( !name ) {
return cutType == 'attributeElement' || super.is( type );
return type === 'attributeElement' || type === 'view:attributeElement' ||
// From super.is(). This is highly utilised method and cannot call super. See ckeditor/ckeditor5#6529.
type === this.name || type === 'view:' + this.name ||
type === 'element' || type === 'view:element' ||
type === 'node' || type === 'view:node';
} else {
return ( cutType == 'attributeElement' && name == this.name ) || super.is( type, name );
return name === this.name && (
type === 'attributeElement' || type === 'view:attributeElement' ||
// From super.is(). This is highly utilised method and cannot call super. See ckeditor/ckeditor5#6529.
type === 'element' || type === 'view:element'
);
}
}

Expand Down
13 changes: 10 additions & 3 deletions packages/ckeditor5-engine/src/view/containerelement.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,18 @@ export default class ContainerElement extends Element {
* @returns {Boolean}
*/
is( type, name = null ) {
const cutType = type && type.replace( /^view:/, '' );
if ( !name ) {
return cutType == 'containerElement' || super.is( type );
return type === 'containerElement' || type === 'view:containerElement' ||
// From super.is(). This is highly utilised method and cannot call super. See ckeditor/ckeditor5#6529.
type === this.name || type === 'view:' + this.name ||
type === 'element' || type === 'view:element' ||
type === 'node' || type === 'view:node';
} else {
return ( cutType == 'containerElement' && name == this.name ) || super.is( type, name );
return name === this.name && (
type === 'containerElement' || type === 'view:containerElement' ||
// From super.is(). This is highly utilised method and cannot call super. See ckeditor/ckeditor5#6529.
type === 'element' || type === 'view:element'
);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/ckeditor5-engine/src/view/documentfragment.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export default class DocumentFragment {
* @returns {Boolean}
*/
is( type ) {
return type == 'documentFragment' || type == 'view:documentFragment';
return type === 'documentFragment' || type === 'view:documentFragment';
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/ckeditor5-engine/src/view/documentselection.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ export default class DocumentSelection {
* @returns {Boolean}
*/
is( type ) {
return type == 'selection' ||
return type === 'selection' ||
type == 'documentSelection' ||
type == 'view:selection' ||
type == 'view:documentSelection';
Expand Down
15 changes: 12 additions & 3 deletions packages/ckeditor5-engine/src/view/editableelement.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,20 @@ export default class EditableElement extends ContainerElement {
* @returns {Boolean}
*/
is( type, name = null ) {
const cutType = type && type.replace( /^view:/, '' );
if ( !name ) {
return cutType == 'editableElement' || super.is( type );
return type === 'editableElement' || type === 'view:editableElement' ||
// From super.is(). This is highly utilised method and cannot call super. See ckeditor/ckeditor5#6529.
type === 'containerElement' || type === 'view:containerElement' ||
type === this.name || type === 'view:' + this.name ||
type === 'element' || type === 'view:element' ||
type === 'node' || type === 'view:node';
} else {
return ( cutType == 'editableElement' && name == this.name ) || super.is( type, name );
return name === this.name && (
type === 'editableElement' || type === 'view:editableElement' ||
// From super.is(). This is highly utilised method and cannot call super. See ckeditor/ckeditor5#6529.
type === 'containerElement' || type === 'view:containerElement' ||
type === 'element' || type === 'view:element'
);
}
}

Expand Down
8 changes: 5 additions & 3 deletions packages/ckeditor5-engine/src/view/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,13 @@ export default class Element extends Node {
* @returns {Boolean}
*/
is( type, name = null ) {
const cutType = type.replace( /^view:/, '' );
if ( !name ) {
return cutType == 'element' || cutType == this.name || super.is( type );
return type === this.name || type === 'view:' + this.name ||
type === 'element' || type === 'view:element' ||
// From super.is(). This is highly utilised method and cannot call super. See ckeditor/ckeditor5#6529.
type === 'node' || type === 'view:node';
} else {
return cutType == 'element' && name == this.name;
return name === this.name && ( type === 'element' || type === 'view:element' );
}
}

Expand Down
12 changes: 9 additions & 3 deletions packages/ckeditor5-engine/src/view/emptyelement.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,17 @@ export default class EmptyElement extends Element {
* @returns {Boolean}
*/
is( type, name = null ) {
const cutType = type.replace( /^view:/, '' );
if ( !name ) {
return cutType == 'emptyElement' || super.is( type );
return type === 'emptyElement' || type === 'view:emptyElement' ||
// From super.is(). This is highly utilised method and cannot call super. See ckeditor/ckeditor5#6529.
type === this.name || type === 'view:' + this.name ||
type === 'element' || type === 'view:element' ||
type === 'node' || type === 'view:node';
} else {
return ( cutType == 'emptyElement' && name == this.name ) || super.is( type, name );
return name === this.name && (
type === 'emptyElement' || type === 'view:emptyElement' ||
type === 'element' || type === 'view:element'
);
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/ckeditor5-engine/src/view/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ export default class Node {
* @returns {Boolean}
*/
is( type ) {
return type == 'node' || type == 'view:node';
return type === 'node' || type === 'view:node';
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/ckeditor5-engine/src/view/position.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ export default class Position {
* @returns {Boolean}
*/
is( type ) {
return type == 'position' || type == 'view:position';
return type === 'position' || type === 'view:position';
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/ckeditor5-engine/src/view/range.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ export default class Range {
* @returns {Boolean}
*/
is( type ) {
return type == 'range' || type == 'view:range';
return type === 'range' || type === 'view:range';
}

/**
Expand Down
17 changes: 14 additions & 3 deletions packages/ckeditor5-engine/src/view/rooteditableelement.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,22 @@ export default class RootEditableElement extends EditableElement {
* @returns {Boolean}
*/
is( type, name = null ) {
const cutType = type.replace( /^view:/, '' );
if ( !name ) {
return cutType == 'rootElement' || super.is( type );
return type === 'rootElement' || type === 'view:rootElement' ||
// From super.is(). This is highly utilised method and cannot call super. See ckeditor/ckeditor5#6529.
type === 'editableElement' || type === 'view:editableElement' ||
type === 'containerElement' || type === 'view:containerElement' ||
type === this.name || type === 'view:' + this.name ||
type === 'element' || type === 'view:element' ||
type === 'node' || type === 'view:node';
} else {
return ( cutType == 'rootElement' && name == this.name ) || super.is( type, name );
return name === this.name && (
type === 'rootElement' || type === 'view:rootElement' ||
// From super.is(). This is highly utilised method and cannot call super. See ckeditor/ckeditor5#6529.
type === 'editableElement' || type === 'view:editableElement' ||
type === 'containerElement' || type === 'view:containerElement' ||
type === 'element' || type === 'view:element'
);
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/ckeditor5-engine/src/view/selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ export default class Selection {
* @returns {Boolean}
*/
is( type ) {
return type == 'selection' || type == 'view:selection';
return type === 'selection' || type === 'view:selection';
}

/**
Expand Down
4 changes: 3 additions & 1 deletion packages/ckeditor5-engine/src/view/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ export default class Text extends Node {
* @returns {Boolean}
*/
is( type ) {
return type == 'text' || type == 'view:text' || super.is( type );
return type === 'text' || type === 'view:text' ||
// From super.is(). This is highly utilised method and cannot call super. See ckeditor/ckeditor5#6529.
type === 'node' || type === 'view:node';
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/ckeditor5-engine/src/view/textproxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export default class TextProxy {
* @returns {Boolean}
*/
is( type ) {
return type == 'textProxy' || type == 'view:textProxy';
return type === 'textProxy' || type === 'view:textProxy';
}

/**
Expand Down
Loading

0 comments on commit 7fafc45

Please sign in to comment.