Skip to content

Commit f5d1dd7

Browse files
committed
use Collator.compare in place of localeCompare
1 parent 6d5183f commit f5d1dd7

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/lib/blocks.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,7 @@ export default function (vm) {
246246
lookupBlocks = vm.runtime.flyoutBlocks;
247247
}
248248
const sort = function (options) {
249-
options.sort((str1, str2) => str1.localeCompare(str2, [], {
250-
sensitivity: 'base',
251-
numeric: true
252-
}));
249+
options.sort(ScratchBlocks.scratchBlocksUtils.compareStrings);
253250
};
254251
// Get all the stage variables (no lists) so we can add them to menu when the stage is selected.
255252
const stageVariableOptions = vm.runtime.getTargetForStage().getAllVariableNamesInScopeByType('');
@@ -323,5 +320,16 @@ export default function (vm) {
323320
vm.runtime.emit('PLAY_NOTE', noteNum, extensionId);
324321
};
325322

323+
// Use a collator's compare instead of localeCompare which internally
324+
// creates a collator. Using this is a lot faster in browsers that create a
325+
// collator for every localeCompare call.
326+
const collator = new Intl.Collator([], {
327+
sensitivity: 'base',
328+
numeric: true
329+
});
330+
ScratchBlocks.scratchBlocksUtils.compareStrings = function (str1, str2) {
331+
return collator.compare(str1, str2);
332+
};
333+
326334
return ScratchBlocks;
327335
}

0 commit comments

Comments
 (0)