chore: Make startsWith faster (#6118)

by using built-in function (polyfill will handle IE).
This commit is contained in:
Neil Fraser
2022-04-27 15:25:07 -07:00
committed by GitHub
parent b1bb5c53b8
commit 63ca83b545
7 changed files with 19 additions and 35 deletions

View File

@@ -19,17 +19,22 @@
*/
goog.module('Blockly.utils.string');
const deprecation = goog.require('Blockly.utils.deprecation');
/**
* Fast prefix-checker.
* Copied from Closure's goog.string.startsWith.
* Obsolete prefix-checker.
* @param {string} str The string to check.
* @param {string} prefix A string to look for at the start of `str`.
* @return {boolean} True if `str` begins with `prefix`.
* @alias Blockly.utils.string.startsWith
* @deprecated April 2022. Use built-in string.startsWith.
*/
const startsWith = function(str, prefix) {
return str.lastIndexOf(prefix, 0) === 0;
deprecation.warn(
'Blockly.utils.string.startsWith()', 'April 2022', 'April 2023',
'Use built-in string.startsWith');
return str.startsWith(prefix);
};
exports.startsWith = startsWith;