mirror of
https://github.com/google/blockly.git
synced 2026-01-09 10:00:09 +01:00
chore: Make startsWith faster (#6118)
by using built-in function (polyfill will handle IE).
This commit is contained in:
@@ -15,7 +15,6 @@
|
||||
goog.module('Blockly.utils.parsing');
|
||||
|
||||
const colourUtils = goog.require('Blockly.utils.colour');
|
||||
const stringUtils = goog.require('Blockly.utils.string');
|
||||
const {Msg} = goog.require('Blockly.Msg');
|
||||
|
||||
|
||||
@@ -97,9 +96,8 @@ const tokenizeInterpolationInternal = function(
|
||||
// BKY_ is the prefix used to namespace the strings used in Blockly
|
||||
// core files and the predefined blocks in ../blocks/.
|
||||
// These strings are defined in ../msgs/ files.
|
||||
const bklyKey = stringUtils.startsWith(keyUpper, 'BKY_') ?
|
||||
keyUpper.substring(4) :
|
||||
null;
|
||||
const bklyKey =
|
||||
keyUpper.startsWith('BKY_') ? keyUpper.substring(4) : null;
|
||||
if (bklyKey && bklyKey in Msg) {
|
||||
const rawValue = Msg[bklyKey];
|
||||
if (typeof rawValue === 'string') {
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user