Skip to content

Commit

Permalink
[Refactor]: stringify/utils: cache Array.isArray
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Feb 3, 2019
1 parent 3cd5200 commit 8297462
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/stringify.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ var normalizeStringifyOptions = function normalizeStringifyOptions(opts) {
var formatter = formats.formatters[format];

var filter = defaults.filter;
if (typeof opts.filter === 'function' || Array.isArray(opts.filter)) {
if (typeof opts.filter === 'function' || isArray(opts.filter)) {
filter = opts.filter;
}

Expand Down
9 changes: 5 additions & 4 deletions lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

var has = Object.prototype.hasOwnProperty;
var isArray = Array.isArray;

var hexTable = (function () {
var array = [];
Expand All @@ -16,7 +17,7 @@ var compactQueue = function compactQueue(queue) {
var item = queue.pop();
var obj = item.obj[item.prop];

if (Array.isArray(obj)) {
if (isArray(obj)) {
var compacted = [];

for (var j = 0; j < obj.length; ++j) {
Expand Down Expand Up @@ -47,7 +48,7 @@ var merge = function merge(target, source, options) {
}

if (typeof source !== 'object') {
if (Array.isArray(target)) {
if (isArray(target)) {
target.push(source);
} else if (target && typeof target === 'object') {
if ((options && (options.plainObjects || options.allowPrototypes)) || !has.call(Object.prototype, source)) {
Expand All @@ -65,11 +66,11 @@ var merge = function merge(target, source, options) {
}

var mergeTarget = target;
if (Array.isArray(target) && !Array.isArray(source)) {
if (isArray(target) && !isArray(source)) {
mergeTarget = arrayToObject(target, options);
}

if (Array.isArray(target) && Array.isArray(source)) {
if (isArray(target) && isArray(source)) {
source.forEach(function (item, i) {
if (has.call(target, i)) {
var targetItem = target[i];
Expand Down

0 comments on commit 8297462

Please sign in to comment.