Avoid creating intermediate strings when not needed.

Former-commit-id: 1e7457ff131f867adbf799e20af11cf714f5da7e
This commit is contained in:
John-David Dalton
2013-03-17 19:31:37 -05:00
parent 2dc539747b
commit d219c6e019

View File

@@ -155,7 +155,7 @@
/** Used to detect if a method is native */ /** Used to detect if a method is native */
var reNative = RegExp('^' + var reNative = RegExp('^' +
(objectRef.valueOf + '') String(objectRef.valueOf)
.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') .replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
.replace(/valueOf|for [^\]]+/g, '.+?') + '$' .replace(/valueOf|for [^\]]+/g, '.+?') + '$'
); );
@@ -372,7 +372,7 @@
* @type Boolean * @type Boolean
*/ */
try { try {
support.nodeClass = !(toString.call(document) == objectClass && !({ 'toString': 0 } + '')); support.nodeClass = !(toString.call(document) == objectClass && !String({ 'toString': 0 }));
} catch(e) { } catch(e) {
support.nodeClass = true; support.nodeClass = true;
} }
@@ -596,13 +596,13 @@
while (++index < length) { while (++index < length) {
// manually coerce `value` to a string because `hasOwnProperty`, in some // manually coerce `value` to a string because `hasOwnProperty`, in some
// older versions of Firefox, coerces objects incorrectly // older versions of Firefox, coerces objects incorrectly
var key = array[index] + ''; var key = String(array[index]);
(hasOwnProperty.call(cache, key) ? cache[key] : (cache[key] = [])).push(array[index]); (hasOwnProperty.call(cache, key) ? cache[key] : (cache[key] = [])).push(array[index]);
} }
} }
return function(value) { return function(value) {
if (isLarge) { if (isLarge) {
var key = value + ''; var key = String(value);
return hasOwnProperty.call(cache, key) && indexOf(cache[key], value) > -1; return hasOwnProperty.call(cache, key) && indexOf(cache[key], value) > -1;
} }
return indexOf(array, value, fromIndex) > -1; return indexOf(array, value, fromIndex) > -1;
@@ -803,7 +803,7 @@
function isNode(value) { function isNode(value) {
// IE < 9 presents DOM nodes as `Object` objects except they have `toString` // IE < 9 presents DOM nodes as `Object` objects except they have `toString`
// methods that are `typeof` "string" and still can coerce nodes to strings // methods that are `typeof` "string" and still can coerce nodes to strings
return typeof value.toString != 'function' && typeof (value + '') == 'string'; return typeof value.toString != 'function' && typeof String(value) == 'string';
} }
/** /**
@@ -1605,7 +1605,7 @@
case stringClass: case stringClass:
// coerce regexes to strings (http://es5.github.com/#x15.10.6.4) // coerce regexes to strings (http://es5.github.com/#x15.10.6.4)
// treat string primitives and their corresponding object instances as equal // treat string primitives and their corresponding object instances as equal
return a == b + ''; return a == String(b);
} }
var isArr = className == arrayClass; var isArr = className == arrayClass;
if (!isArr) { if (!isArr) {
@@ -2343,7 +2343,7 @@
callback = lodash.createCallback(callback, thisArg); callback = lodash.createCallback(callback, thisArg);
forEach(collection, function(value, key, collection) { forEach(collection, function(value, key, collection) {
key = callback(value, key, collection) + ''; key = String(callback(value, key, collection));
(hasOwnProperty.call(result, key) ? result[key]++ : result[key] = 1); (hasOwnProperty.call(result, key) ? result[key]++ : result[key] = 1);
}); });
return result; return result;
@@ -2618,7 +2618,7 @@
callback = lodash.createCallback(callback, thisArg); callback = lodash.createCallback(callback, thisArg);
forEach(collection, function(value, key, collection) { forEach(collection, function(value, key, collection) {
key = callback(value, key, collection) + ''; key = String(callback(value, key, collection));
(hasOwnProperty.call(result, key) ? result[key] : result[key] = []).push(value); (hasOwnProperty.call(result, key) ? result[key] : result[key] = []).push(value);
}); });
return result; return result;
@@ -3623,7 +3623,7 @@
while (++index < length) { while (++index < length) {
var value = array[index]; var value = array[index];
if (isLarge) { if (isLarge) {
var key = value + ''; var key = String(value);
var inited = hasOwnProperty.call(cache[0], key) var inited = hasOwnProperty.call(cache[0], key)
? !(seen = cache[0][key]) ? !(seen = cache[0][key])
: (seen = cache[0][key] = []); : (seen = cache[0][key] = []);
@@ -4031,7 +4031,7 @@
computed = callback ? callback(value, index, array) : value; computed = callback ? callback(value, index, array) : value;
if (isLarge) { if (isLarge) {
var key = computed + ''; var key = String(computed);
var inited = hasOwnProperty.call(cache, key) var inited = hasOwnProperty.call(cache, key)
? !(seen = cache[key]) ? !(seen = cache[key])
: (seen = cache[key] = []); : (seen = cache[key] = []);
@@ -4517,7 +4517,7 @@
function memoize(func, resolver) { function memoize(func, resolver) {
var cache = {}; var cache = {};
return function() { return function() {
var key = (resolver ? resolver.apply(this, arguments) : arguments[0]) + ''; var key = String(resolver ? resolver.apply(this, arguments) : arguments[0]);
return hasOwnProperty.call(cache, key) return hasOwnProperty.call(cache, key)
? cache[key] ? cache[key]
: (cache[key] = func.apply(this, arguments)); : (cache[key] = func.apply(this, arguments));
@@ -4707,7 +4707,7 @@
* // => 'Moe, Larry &amp; Curly' * // => 'Moe, Larry &amp; Curly'
*/ */
function escape(string) { function escape(string) {
return string == null ? '' : (string + '').replace(reUnescapedHtml, escapeHtmlChar); return string == null ? '' : String(string).replace(reUnescapedHtml, escapeHtmlChar);
} }
/** /**
@@ -5102,7 +5102,7 @@
* // => 'Moe, Larry & Curly' * // => 'Moe, Larry & Curly'
*/ */
function unescape(string) { function unescape(string) {
return string == null ? '' : (string + '').replace(reEscapedHtml, unescapeHtmlChar); return string == null ? '' : String(string).replace(reEscapedHtml, unescapeHtmlChar);
} }
/** /**
@@ -5123,7 +5123,7 @@
*/ */
function uniqueId(prefix) { function uniqueId(prefix) {
var id = ++idCounter; var id = ++idCounter;
return (prefix == null ? '' : prefix + '') + id; return String(prefix == null ? '' : prefix) + id;
} }
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
@@ -5167,7 +5167,7 @@
* // => '1,2,3' * // => '1,2,3'
*/ */
function wrapperToString() { function wrapperToString() {
return this.__wrapped__ + ''; return String(this.__wrapped__);
} }
/** /**