mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 18:17:48 +00:00
Exit early in baseToString if value is already a string.
This commit is contained in:
16
lodash.js
16
lodash.js
@@ -793,14 +793,18 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts `value` to a string. An empty string is returned for `null`
|
* Converts `value` to a string if it's not one.
|
||||||
* and `undefined` values.
|
* An empty string is returned for `null` and `undefined` values.
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
* @param {*} value The value to convert.
|
* @param {*} value The value to process.
|
||||||
* @returns {string} Returns the converted string.
|
* @returns {string} Returns the string.
|
||||||
*/
|
*/
|
||||||
function baseToString(value) {
|
function baseToString(value) {
|
||||||
|
// Exit early for strings to avoid a performance hit in some environments.
|
||||||
|
if (typeof value == 'string') {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
return value == null ? '' : (value + '');
|
return value == null ? '' : (value + '');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4523,7 +4527,7 @@
|
|||||||
* Converts `value` to a function if it's not one.
|
* Converts `value` to a function if it's not one.
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
* @param {*} value The value to convert.
|
* @param {*} value The value to process.
|
||||||
* @returns {Function} Returns the function.
|
* @returns {Function} Returns the function.
|
||||||
*/
|
*/
|
||||||
function toFunction(value) {
|
function toFunction(value) {
|
||||||
@@ -10526,7 +10530,7 @@
|
|||||||
*/
|
*/
|
||||||
function endsWith(string, target, position) {
|
function endsWith(string, target, position) {
|
||||||
string = baseToString(string);
|
string = baseToString(string);
|
||||||
target = (target + '');
|
target = typeof target == 'string' ? target : (target + '');
|
||||||
|
|
||||||
var length = string.length;
|
var length = string.length;
|
||||||
position = position === undefined
|
position = position === undefined
|
||||||
|
|||||||
Reference in New Issue
Block a user