From f5d1dd7e035340489da2d1185175d1797fb33cb5 Mon Sep 17 00:00:00 2001 From: "Michael \"Z\" Goddard" Date: Wed, 13 Mar 2019 15:06:29 -0400 Subject: [PATCH] use Collator.compare in place of localeCompare --- src/lib/blocks.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/lib/blocks.js b/src/lib/blocks.js index 9ca3c6d7e..310f22c23 100644 --- a/src/lib/blocks.js +++ b/src/lib/blocks.js @@ -246,10 +246,7 @@ export default function (vm) { lookupBlocks = vm.runtime.flyoutBlocks; } const sort = function (options) { - options.sort((str1, str2) => str1.localeCompare(str2, [], { - sensitivity: 'base', - numeric: true - })); + options.sort(ScratchBlocks.scratchBlocksUtils.compareStrings); }; // Get all the stage variables (no lists) so we can add them to menu when the stage is selected. const stageVariableOptions = vm.runtime.getTargetForStage().getAllVariableNamesInScopeByType(''); @@ -323,5 +320,16 @@ export default function (vm) { vm.runtime.emit('PLAY_NOTE', noteNum, extensionId); }; + // Use a collator's compare instead of localeCompare which internally + // creates a collator. Using this is a lot faster in browsers that create a + // collator for every localeCompare call. + const collator = new Intl.Collator([], { + sensitivity: 'base', + numeric: true + }); + ScratchBlocks.scratchBlocksUtils.compareStrings = function (str1, str2) { + return collator.compare(str1, str2); + }; + return ScratchBlocks; }