8
0
Pārlūkot izejas kodu

Merge pull request #323 from ckeditor/i/5854

Other: Improved `toMap` method performance. This results in improved editor data processing speed. Closes ckeditor/ckeditor5#5854.
Maciej 5 gadi atpakaļ
vecāks
revīzija
56ef368d73

+ 2 - 0
packages/ckeditor5-utils/src/objecttomap.js

@@ -13,6 +13,8 @@
  *		const map = objectToMap( { 'foo': 1, 'bar': 2 } );
  *		map.get( 'foo' ); // 1
  *
+ * **Note**: For mixed data (`Object` or `Iterable`) there's a dedicated {@link module:utils/tomap~toMap} function.
+ *
  * @param {Object} obj Object to transform.
  * @returns {Map} Map created from object.
  */

+ 4 - 4
packages/ckeditor5-utils/src/tomap.js

@@ -8,7 +8,7 @@
  */
 
 import objectToMap from './objecttomap';
-import { isPlainObject } from 'lodash-es';
+import isIterable from './isiterable';
 
 /**
  * Transforms object or iterable to map. Iterable needs to be in the format acceptable by the `Map` constructor.
@@ -21,9 +21,9 @@ import { isPlainObject } from 'lodash-es';
  * @returns {Map} Map created from data.
  */
 export default function toMap( data ) {
-	if ( isPlainObject( data ) ) {
-		return objectToMap( data );
-	} else {
+	if ( isIterable( data ) ) {
 		return new Map( data );
+	} else {
+		return objectToMap( data );
 	}
 }