Skip to content

Commit 70cda32

Browse files
authored
fix: Improve performance of variable name comparisons (#10175)
1 parent 176da11 commit 70cda32

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

packages/blockly/core/variables.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ import * as utilsXml from './utils/xml.js';
2323
import type {Workspace} from './workspace.js';
2424
import type {WorkspaceSvg} from './workspace_svg.js';
2525

26+
const nameComparisonCollator = new Intl.Collator(undefined, {
27+
sensitivity: 'base',
28+
});
29+
2630
/**
2731
* String for use in the "custom" attribute of a category in toolbox XML.
2832
* This string indicates that the category should be dynamically populated with
@@ -805,9 +809,7 @@ export function compareByName(
805809
var1: IVariableModel<IVariableState>,
806810
var2: IVariableModel<IVariableState>,
807811
): number {
808-
return var1
809-
.getName()
810-
.localeCompare(var2.getName(), undefined, {sensitivity: 'base'});
812+
return nameComparisonCollator.compare(var1.getName(), var2.getName());
811813
}
812814

813815
/**

0 commit comments

Comments
 (0)