Remove toIterable and toObject.

This commit is contained in:
John-David Dalton
2015-07-15 07:58:25 -07:00
parent e6b9aaf499
commit 192e35882a

View File

@@ -1963,15 +1963,14 @@
if (object == null) { if (object == null) {
return; return;
} }
object = toObject(object); if (pathKey !== undefined && pathKey in Object(object)) {
if (pathKey !== undefined && pathKey in object) {
path = [pathKey]; path = [pathKey];
} }
var index = 0, var index = 0,
length = path.length; length = path.length;
while (object != null && index < length) { while (object != null && index < length) {
object = toObject(object)[path[index++]]; object = object[path[index++]];
} }
return (index && index == length) ? object : undefined; return (index && index == length) ? object : undefined;
} }
@@ -2094,7 +2093,7 @@
if (object == null) { if (object == null) {
return !length; return !length;
} }
object = toObject(object); object = Object(object);
while (index--) { while (index--) {
var data = matchData[index]; var data = matchData[index];
if ((noCustomizer && data[2]) if ((noCustomizer && data[2])
@@ -2212,8 +2211,7 @@
if (object == null) { if (object == null) {
return false; return false;
} }
object = toObject(object); return object[key] === value && (value !== undefined || (key in Object(object)));
return object[key] === value && (value !== undefined || (key in object));
}; };
} }
return function(object) { return function(object) {
@@ -2240,17 +2238,15 @@
return false; return false;
} }
var key = pathKey; var key = pathKey;
object = toObject(object); if ((isArr || !isCommon) && !(key in Object(object))) {
if ((isArr || !isCommon) && !(key in object)) {
object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1)); object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
if (object == null) { if (object == null) {
return false; return false;
} }
key = last(path); key = last(path);
object = toObject(object);
} }
return object[key] === srcValue return object[key] === srcValue
? (srcValue !== undefined || (key in object)) ? (srcValue !== undefined || (key in Object(object)))
: baseIsEqual(srcValue, object[key], undefined, true); : baseIsEqual(srcValue, object[key], undefined, true);
}; };
} }
@@ -2364,7 +2360,7 @@
* @returns {Object} Returns the new object. * @returns {Object} Returns the new object.
*/ */
function basePick(object, props) { function basePick(object, props) {
object = toObject(object); object = Object(object);
var index = -1, var index = -1,
length = props.length, length = props.length,
@@ -2406,7 +2402,7 @@
*/ */
function baseProperty(key) { function baseProperty(key) {
return function(object) { return function(object) {
return object == null ? undefined : toObject(object)[key]; return object == null ? undefined : object[key];
}; };
} }
@@ -2987,7 +2983,7 @@
customizer = length < 3 ? undefined : customizer; customizer = length < 3 ? undefined : customizer;
length = 1; length = 1;
} }
object = toObject(object); object = Object(object);
while (++index < length) { while (++index < length) {
var source = sources[index]; var source = sources[index];
if (source) { if (source) {
@@ -3016,7 +3012,7 @@
} }
var length = collection.length, var length = collection.length,
index = fromRight ? length : -1, index = fromRight ? length : -1,
iterable = toObject(collection); iterable = Object(collection);
while ((fromRight ? index-- : ++index < length)) { while ((fromRight ? index-- : ++index < length)) {
if (iteratee(iterable[index], index, iterable) === false) { if (iteratee(iterable[index], index, iterable) === false) {
@@ -3036,7 +3032,7 @@
*/ */
function createBaseFor(fromRight) { function createBaseFor(fromRight) {
return function(object, iteratee, keysFunc) { return function(object, iteratee, keysFunc) {
var iterable = toObject(object), var iterable = Object(object),
props = keysFunc(object), props = keysFunc(object),
length = props.length, length = props.length,
index = fromRight ? length : -1; index = fromRight ? length : -1;
@@ -3907,7 +3903,7 @@
return false; return false;
} }
var result = !reIsDeepProp.test(value); var result = !reIsDeepProp.test(value);
return result || (object != null && value in toObject(object)); return result || (object != null && value in Object(object));
} }
/** /**
@@ -4123,47 +4119,6 @@
return typeof func == 'function' ? func : identity; return typeof func == 'function' ? func : identity;
} }
/**
* Converts `value` to an array-like object if it's not one.
*
* @private
* @param {*} value The value to process.
* @returns {Array|Object} Returns the array-like object.
*/
function toIterable(value) {
if (value == null) {
return [];
}
if (!isArrayLike(value)) {
return values(value);
}
if (isString(value)) {
return value.split('');
}
return isObject(value) ? value : Object(value);
}
/**
* Converts `value` to an object if it's not one.
*
* @private
* @param {*} value The value to process.
* @returns {Object} Returns the object.
*/
function toObject(value) {
if (isString(value)) {
var index = -1,
length = value.length,
result = Object(value);
while (++index < length) {
result[index] = value.charAt(index);
}
return result;
}
return isObject(value) ? value : Object(value);
}
/** /**
* Converts `value` to property path array if it's not one. * Converts `value` to property path array if it's not one.
* *
@@ -5671,7 +5626,7 @@
var wrapperConcat = restParam(function(values) { var wrapperConcat = restParam(function(values) {
values = baseFlatten(values); values = baseFlatten(values);
return this.thru(function(array) { return this.thru(function(array) {
return arrayConcat(isArray(array) ? array : [toObject(array)], values); return arrayConcat(isArray(array) ? array : [Object(array)], values);
}); });
}); });
@@ -5810,7 +5765,6 @@
* // => ['barney', 'pebbles'] * // => ['barney', 'pebbles']
*/ */
var at = restParam(function(collection, props) { var at = restParam(function(collection, props) {
collection = isArrayLike(collection) ? toIterable(collection) : collection;
return baseAt(collection, baseFlatten(props)); return baseAt(collection, baseFlatten(props));
}); });
@@ -6407,7 +6361,7 @@
*/ */
function sample(collection, n, guard) { function sample(collection, n, guard) {
if (guard ? isIterateeCall(collection, n, guard) : n == null) { if (guard ? isIterateeCall(collection, n, guard) : n == null) {
collection = toIterable(collection); collection = isArrayLike(collection) ? collection : values(collection);
var length = collection.length; var length = collection.length;
return length > 0 ? collection[baseRandom(0, length - 1)] : undefined; return length > 0 ? collection[baseRandom(0, length - 1)] : undefined;
} }
@@ -8479,10 +8433,7 @@
if (!isArrayLike(value)) { if (!isArrayLike(value)) {
return values(value); return values(value);
} }
if (!value.length) { return value.length ? copyArray(value) : [];
return [];
}
return copyArray(toObject(value));
} }
/** /**
@@ -9049,7 +9000,7 @@
* // => ['0', '1'] * // => ['0', '1']
*/ */
function keys(object) { function keys(object) {
object = toObject(object); object = Object(object);
var isProto = isPrototype(object); var isProto = isPrototype(object);
if (!(isProto || isArrayLike(object))) { if (!(isProto || isArrayLike(object))) {
@@ -9092,7 +9043,7 @@
* // => ['a', 'b', 'c'] (iteration order is not guaranteed) * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
*/ */
function keysIn(object) { function keysIn(object) {
object = toObject(object); object = Object(object);
var index = -1, var index = -1,
isProto = isPrototype(object), isProto = isPrototype(object),
@@ -9306,7 +9257,7 @@
* // => [['barney', 36], ['fred', 40]] (iteration order is not guaranteed) * // => [['barney', 36], ['fred', 40]] (iteration order is not guaranteed)
*/ */
function pairs(object) { function pairs(object) {
object = toObject(object); object = Object(object);
var index = -1, var index = -1,
props = keys(object), props = keys(object),
@@ -9391,12 +9342,12 @@
* // => 'default' * // => 'default'
*/ */
function result(object, path, defaultValue) { function result(object, path, defaultValue) {
var result = object == null ? undefined : toObject(object)[path]; var result = object == null ? undefined : object[path];
if (result === undefined) { if (result === undefined) {
if (object != null && !isKey(path, object)) { if (object != null && !isKey(path, object)) {
path = toPath(path); path = toPath(path);
object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1)); object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
result = object == null ? undefined : toObject(object)[last(path)]; result = object == null ? undefined : object[last(path)];
} }
result = result === undefined ? defaultValue : result; result = result === undefined ? defaultValue : result;
} }