Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit af872c6

Browse files
authored
Execute getListItemCount() only once
Better for performance
1 parent 5cb7dfd commit af872c6

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

packages/mdc-list/foundation.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ export class MDCListFoundation extends MDCFoundation<MDCListAdapter> {
140140
* initializes the internal state to match the selected item.
141141
*/
142142
private maybeInitializeSingleSelection() {
143-
for (let i = 0; i < this.adapter.getListItemCount(); i++) {
143+
const listItemsCount = this.adapter.getListItemCount();
144+
for (let i = 0; i < listItemsCount; i++) {
144145
const hasSelectedClass = this.adapter.listItemAtIndexHasClass(
145146
i, cssClasses.LIST_ITEM_SELECTED_CLASS);
146147
const hasActivatedClass = this.adapter.listItemAtIndexHasClass(

0 commit comments

Comments
 (0)