Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.

Commit fef816e

Browse files
authored
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.
2 parents b57fc3f + b1bf335 commit fef816e

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/objecttomap.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
* const map = objectToMap( { 'foo': 1, 'bar': 2 } );
1414
* map.get( 'foo' ); // 1
1515
*
16+
* **Note**: For mixed data (`Object` or `Iterable`) there's a dedicated {@link module:utils/tomap~toMap} function.
17+
*
1618
* @param {Object} obj Object to transform.
1719
* @returns {Map} Map created from object.
1820
*/

src/tomap.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
import objectToMap from './objecttomap';
11-
import { isPlainObject } from 'lodash-es';
11+
import isIterable from './isiterable';
1212

1313
/**
1414
* 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';
2121
* @returns {Map} Map created from data.
2222
*/
2323
export default function toMap( data ) {
24-
if ( isPlainObject( data ) ) {
25-
return objectToMap( data );
26-
} else {
24+
if ( isIterable( data ) ) {
2725
return new Map( data );
26+
} else {
27+
return objectToMap( data );
2828
}
2929
}

0 commit comments

Comments
 (0)