From f62d397a0d238029ba12a450f453b83addef1cee Mon Sep 17 00:00:00 2001 From: Marek Lewandowski Date: Tue, 19 Nov 2019 13:35:24 +0100 Subject: [PATCH 1/3] Internal: Further improved performance by cheaper type checks. The isPlainObject method is pretty slow, and given that elements are created intensively, reducing cost of this brings notable gains. --- src/view/element.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/view/element.js b/src/view/element.js index 78e47459d..4f588d235 100644 --- a/src/view/element.js +++ b/src/view/element.js @@ -859,10 +859,10 @@ export default class Element extends Node { // @param {Object|Map} attrs Attributes to parse. // @returns {Map} Parsed attributes. function parseAttributes( attrs ) { - if ( isPlainObject( attrs ) ) { - attrs = objectToMap( attrs ); - } else { + if ( attrs instanceof Map ) { attrs = new Map( attrs ); + } else { + attrs = objectToMap( attrs ); } for ( const [ key, value ] of attrs ) { From e72e2161b465b3a1a410c37b2cfd7b8fe9ec6264 Mon Sep 17 00:00:00 2001 From: Marek Lewandowski Date: Wed, 20 Nov 2019 10:28:43 +0100 Subject: [PATCH 2/3] Internal: Reuse existing function to create a Map. Also fixed API docs, as the function is supposed to work with Iterables, see the attrs parameter type in view/Element's constructor (https://ckeditor.com/docs/ckeditor5/15.0.0/api/module_engine_view_element-Element.html#function-constructor). --- src/view/element.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/view/element.js b/src/view/element.js index 4f588d235..87abe5fe2 100644 --- a/src/view/element.js +++ b/src/view/element.js @@ -10,7 +10,7 @@ import Node from './node'; import Text from './text'; import TextProxy from './textproxy'; -import objectToMap from '@ckeditor/ckeditor5-utils/src/objecttomap'; +import toMap from '@ckeditor/ckeditor5-utils/src/tomap'; import isIterable from '@ckeditor/ckeditor5-utils/src/isiterable'; import Matcher from './matcher'; import { isPlainObject } from 'lodash-es'; @@ -853,17 +853,13 @@ export default class Element extends Node { } // Parses attributes provided to the element constructor before they are applied to an element. If attributes are passed -// as an object (instead of `Map`), the object is transformed to the map. Attributes with `null` value are removed. +// as an object (instead of `Iterable`), the object is transformed to the map. Attributes with `null` value are removed. // Attributes with non-`String` value are converted to `String`. // -// @param {Object|Map} attrs Attributes to parse. +// @param {Object|Iterable} attrs Attributes to parse. // @returns {Map} Parsed attributes. function parseAttributes( attrs ) { - if ( attrs instanceof Map ) { - attrs = new Map( attrs ); - } else { - attrs = objectToMap( attrs ); - } + attrs = toMap( attrs ); for ( const [ key, value ] of attrs ) { if ( value === null ) { From 56bd2401729bb77ba1259f147f7adca6e68f3fdb Mon Sep 17 00:00:00 2001 From: Marek Lewandowski Date: Wed, 5 Feb 2020 15:24:06 +0100 Subject: [PATCH 3/3] Internal: Removed unused reference. --- src/view/element.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/view/element.js b/src/view/element.js index 87abe5fe2..be74c983b 100644 --- a/src/view/element.js +++ b/src/view/element.js @@ -13,7 +13,6 @@ import TextProxy from './textproxy'; import toMap from '@ckeditor/ckeditor5-utils/src/tomap'; import isIterable from '@ckeditor/ckeditor5-utils/src/isiterable'; import Matcher from './matcher'; -import { isPlainObject } from 'lodash-es'; import StylesMap from './stylesmap'; // @if CK_DEBUG_ENGINE // const { convertMapToTags } = require( '../dev-utils/utils' );