@@ -123,8 +123,12 @@ public void OnGUI(Rect rect, GUIContent label = null, SerializedProperty propert
123123 return ;
124124 }
125125
126- ////TODO: this should be cached; generates needless GC churn
127- var displayName = InputControlPath . ToHumanReadableString ( path ) ;
126+ // Cache the display name per path value and only recompute when the string actually changes.
127+ if ( ! string . Equals ( path , m_CachedPath , StringComparison . InvariantCultureIgnoreCase ) )
128+ {
129+ m_CachedPath = path ;
130+ m_CachedDisplayName = InputControlPath . ToHumanReadableString ( path ) ;
131+ }
128132
129133 // Either show dropdown control that opens path picker or show path directly as
130134 // text, if manual path editing is toggled on.
@@ -146,7 +150,7 @@ public void OnGUI(Rect rect, GUIContent label = null, SerializedProperty propert
146150 else
147151 {
148152 // Dropdown that shows binding text and allows opening control picker.
149- if ( EditorGUI . DropdownButton ( bindingTextRect , new GUIContent ( displayName ) , FocusType . Keyboard ) )
153+ if ( EditorGUI . DropdownButton ( bindingTextRect , new GUIContent ( m_CachedDisplayName ) , FocusType . Keyboard ) )
150154 {
151155 SetExpectedControlLayoutFromAttribute ( serializedProperty ) ;
152156 ////TODO: for bindings that are part of composites, use the layout information from the [InputControl] attribute on the field
@@ -209,6 +213,9 @@ private void SetExpectedControlLayoutFromAttribute(SerializedProperty property)
209213 private string m_ExpectedControlLayout ;
210214 private string [ ] m_ControlPathsToMatch ;
211215
216+ private string m_CachedPath ;
217+ private string m_CachedDisplayName ;
218+
212219 private InputControlPickerDropdown m_PickerDropdown ;
213220 private readonly InputControlPickerState m_PickerState ;
214221
0 commit comments