@@ -358,6 +358,21 @@ abstract class UiComponent2<TProps extends UiProps> extends react.Component2
358358 @toBeGenerated
359359 PropsMetaCollection get propsMeta => throw UngeneratedError (member: #propsMeta);
360360
361+ /// Cache the flattened consumed prop keys to avoid rebuilding on every call.
362+ /// This is lazily initialized and computed only once per component instance.
363+ HashSet <String >? _cachedConsumedPropKeys;
364+
365+ /// Returns the cached flattened set of consumed prop keys, computing it if necessary.
366+ HashSet <String >? get _consumedPropKeys {
367+ if (_cachedConsumedPropKeys == null && consumedProps != null ) {
368+ _cachedConsumedPropKeys = consumedProps! .fold (
369+ HashSet <String >(),
370+ (set , consumedProps) => set ? ..addAll (consumedProps.keys)
371+ );
372+ }
373+ return _cachedConsumedPropKeys;
374+ }
375+
361376 /// A prop modifier that passes a reference of a component's `props` to be updated with any unconsumed props.
362377 ///
363378 /// Call within `modifyProps` like so:
@@ -373,10 +388,7 @@ abstract class UiComponent2<TProps extends UiProps> extends react.Component2
373388 ///
374389 /// > Related [addUnconsumedDomProps]
375390 void addUnconsumedProps (Map props) {
376- // TODO: cache this value to avoid unnecessary looping
377- var consumedPropKeys = consumedProps? .fold (HashSet <String >(), (set , consumedProps) => set ..addAll (consumedProps.keys));
378-
379- forwardUnconsumedPropsV2 (this .props, propsToUpdate: props, keysToOmit: consumedPropKeys);
391+ forwardUnconsumedPropsV2 (this .props, propsToUpdate: props, keysToOmit: _consumedPropKeys);
380392 }
381393
382394 /// A prop modifier that passes a reference of a component's `props` to be updated with any unconsumed `DomProps` .
@@ -394,9 +406,7 @@ abstract class UiComponent2<TProps extends UiProps> extends react.Component2
394406 ///
395407 /// > Related [addUnconsumedProps]
396408 void addUnconsumedDomProps (Map props) {
397- var consumedPropKeys = consumedProps? .fold (HashSet <String >(), (set , consumedProps) => set ..addAll (consumedProps.keys));
398-
399- forwardUnconsumedPropsV2 (this .props, propsToUpdate: props, keysToOmit: consumedPropKeys, onlyCopyDomProps: true );
409+ forwardUnconsumedPropsV2 (this .props, propsToUpdate: props, keysToOmit: _consumedPropKeys, onlyCopyDomProps: true );
400410 }
401411
402412 /// Returns a copy of this component's props with React props optionally omitted, and
0 commit comments