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

Commit

Permalink
Merge pull request #323 from ckeditor/i/5854
Browse files Browse the repository at this point in the history
Other: Improved `toMap` method performance. This results in improved editor data processing speed. Closes ckeditor/ckeditor5#5854.
  • Loading branch information
jodator authored Feb 6, 2020
2 parents b57fc3f + b1bf335 commit fef816e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/objecttomap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
8 changes: 4 additions & 4 deletions src/tomap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 );
}
}

0 comments on commit fef816e

Please sign in to comment.