Skip to content

FIX: Performance Improvements #1578

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Packages/com.unity.inputsystem/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ however, it has to be formatted properly to pass verification tests.
- Fix for mitigating symptoms reported in ([case UUM-10774](https://issuetracker.unity3d.com/product/unity/issues/guid/UUM-10774) effectively avoiding reenabling mouse, pen or touch devices in `InputSystemPlugin.OnDestroy()` if currently quitting the editor. The fix avoids editor crashing if closed when Simulator Window is open. Note that the actual issue needs a separate fix in Unity and this package fix is only to avoid running into the issue.
- Fixed an issue where Input Action name would not display correctly in Inspector if serialized as `[SerializedProperty]` within a class not derived from `MonoBehavior` ([case ISXB-124](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-124).
- Fix an issue where users could end up with the wrong device assignments when using the InputUser API directly and removing a user ([case ISXB-274](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-231)).
- Improved performance of editor and runtime behavior

## [1.4.2] - 2022-08-12

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1550,10 +1550,7 @@ internal bool ActiveControlIsValid(InputControl control)
// must be in list.
var map = GetOrCreateActionMap();
var deviceList = map.devices;
if (deviceList != null && !deviceList.Value.ContainsReference(device))
return false;

return true;
return deviceList == null || deviceList.Value.ContainsReference(device);
}

internal InputBinding? FindEffectiveBindingMask()
Expand Down Expand Up @@ -1609,7 +1606,7 @@ internal int BindingIndexOnMapToBindingIndexOnAction(int indexOfBindingOnMap)
{
ref var binding = ref bindingsInMap[i];

if (string.Compare(binding.action, actionName, StringComparison.InvariantCultureIgnoreCase) == 0 ||
if (string.Equals(binding.action, actionName, StringComparison.InvariantCultureIgnoreCase) ||
binding.action == m_Id)
++bindingIndexOnAction;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ public InputActionMap FindActionMap(string nameOrId, bool throwIfNotFound = fals
for (var i = 0; i < m_ActionMaps.Length; ++i)
{
var map = m_ActionMaps[i];
if (string.Compare(nameOrId, map.name, StringComparison.InvariantCultureIgnoreCase) == 0)
if (string.Equals(nameOrId, map.name, StringComparison.InvariantCultureIgnoreCase))
return map;
}

Expand Down Expand Up @@ -718,7 +718,7 @@ public int FindControlSchemeIndex(string name)
return -1;

for (var i = 0; i < m_ControlSchemes.Length; ++i)
if (string.Compare(name, m_ControlSchemes[i].name, StringComparison.InvariantCultureIgnoreCase) == 0)
if (string.Equals(name, m_ControlSchemes[i].name, StringComparison.InvariantCultureIgnoreCase))
return i;

return -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ internal int FindActionIndex(string nameOrId)
for (var i = 0; i < actionCount; ++i)
{
var action = m_Actions[i];
if (action.m_Id == nameOrId || string.Compare(m_Actions[i].m_Name, nameOrId, StringComparison.InvariantCultureIgnoreCase) == 0)
if (action.m_Id == nameOrId || string.Equals(m_Actions[i].m_Name, nameOrId, StringComparison.InvariantCultureIgnoreCase))
return i;
}

Expand Down Expand Up @@ -1723,7 +1723,7 @@ public InputActionMap[] ToMaps()
var mapIndex = 0;
for (; mapIndex < mapList.Count; ++mapIndex)
{
if (string.Compare(mapList[mapIndex].name, mapName, StringComparison.InvariantCultureIgnoreCase) == 0)
if (string.Equals(mapList[mapIndex].name, mapName, StringComparison.InvariantCultureIgnoreCase))
{
map = mapList[mapIndex];
break;
Expand Down Expand Up @@ -1774,7 +1774,7 @@ public InputActionMap[] ToMaps()
var mapIndex = 0;
for (; mapIndex < mapList.Count; ++mapIndex)
{
if (string.Compare(mapList[mapIndex].name, mapName, StringComparison.InvariantCultureIgnoreCase) == 0)
if (string.Equals(mapList[mapIndex].name, mapName, StringComparison.InvariantCultureIgnoreCase))
{
map = mapList[mapIndex];
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ public static void Rename(this InputAction action, string newName)
var bindings = action.GetOrCreateActionMap().m_Bindings;
var bindingCount = bindings.LengthSafe();
for (var i = 0; i < bindingCount; ++i)
if (string.Compare(bindings[i].action, oldName, StringComparison.InvariantCultureIgnoreCase) == 0)
if (string.Equals(bindings[i].action, oldName, StringComparison.InvariantCultureIgnoreCase))
bindings[i].action = newName;
}

Expand Down Expand Up @@ -1368,15 +1368,13 @@ private BindingSyntax Iterate(bool next)
// To find the next binding for a specific action, we may have to jump
// over unrelated bindings in-between.
var index = m_BindingIndexInMap;
while (true)
do
{
index += next ? 1 : -1;
if (index < 0 || index >= bindings.Length)
return default;

if (m_Action == null || bindings[index].TriggersAction(m_Action))
break;
}
while (m_Action != null && !bindings[index].TriggersAction(m_Action));

return new BindingSyntax(m_ActionMap, index, m_Action);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ public string ToDisplayString(out string deviceLayoutName, out string controlPat
internal bool TriggersAction(InputAction action)
{
// Match both name and ID on binding.
return string.Compare(action.name, this.action, StringComparison.InvariantCultureIgnoreCase) == 0
return string.Equals(action.name, this.action, StringComparison.InvariantCultureIgnoreCase)
|| this.action == action.m_Id;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,8 @@ public string shortDisplayName
get
{
RefreshConfigurationIfNeeded();
if (m_ShortDisplayName != null)
return m_ShortDisplayName;
if (m_ShortDisplayNameFromLayout != null)
return m_ShortDisplayNameFromLayout;
return null;

return m_ShortDisplayName != null ? m_ShortDisplayName : m_ShortDisplayNameFromLayout;
}
protected set => m_ShortDisplayName = value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,7 @@ public static bool IsActuated(this InputControl control, float threshold = 0)
//
// If we're looking for a specific threshold here, consider the control to always
// be under. But if not, consider it actuated "by virtue of not being in default state".
if (Mathf.Approximately(threshold, 0))
return true;
return false;
return Mathf.Approximately(threshold, 0);
}

if (Mathf.Approximately(threshold, 0))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ public ControlItem this[string path]
for (var i = 0; i < m_Controls.Length; ++i)
{
ref var control = ref m_Controls[i];
if (string.Compare(control.name, path, StringComparison.InvariantCultureIgnoreCase) == 0)
if (string.Equals(control.name, path, StringComparison.InvariantCultureIgnoreCase))
return control;

////FIXME: what this can't handle is "outerArray4/innerArray5"; not sure we care, though
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -751,10 +751,8 @@ public static bool MatchesPrefix(string expected, InputControl control)
throw new ArgumentNullException(nameof(control));

var parser = new PathParser(expected);
if (MatchesRecursive(ref parser, control, prefixOnly: true) && parser.isAtEnd)
return true;

return false;
return MatchesRecursive(ref parser, control, prefixOnly: true) && parser.isAtEnd;
}

private static bool MatchesRecursive(ref PathParser parser, InputControl currentControl, bool prefixOnly = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public bool Equals(InputDeviceDescription other)
/// <seealso cref="Equals(InputDeviceDescription)"/>
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
if (obj is null)
return false;
return obj is InputDeviceDescription description && Equals(description);
}
Expand Down Expand Up @@ -387,9 +387,7 @@ internal static bool ComparePropertyToDeviceDescriptor(string propertyName, stri
var json = new JsonParser(deviceDescriptor);
if (!json.NavigateToProperty(propertyName))
{
if (string.IsNullOrEmpty(propertyValue))
return true;
return false;
return string.IsNullOrEmpty(propertyValue);
}

return json.CurrentPropertyHasValueEqualTo(propertyValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ private static bool MatchSingleProperty(object pattern, string value)
{
// String match.
if (pattern is string str)
return string.Compare(str, value, StringComparison.InvariantCultureIgnoreCase) == 0;
return string.Equals(str, value, StringComparison.InvariantCultureIgnoreCase);

// Regex match.
if (pattern is Regex regex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ public IEnumerable<TItem> GetSelectedItemsOrParentsOfType<TItem>()

public void SelectFirstToplevelItem()
{
if (rootItem.children.Any())
if (rootItem.children.Count > 0)
SetSelection(new[] {rootItem.children[0].id}, TreeViewSelectionOptions.FireSelectionChanged);
}

Expand Down Expand Up @@ -773,7 +773,7 @@ private void PasteBlocks(string transmission, InsertLocation location, bool assi
if (blocks.Length < 1)
return;

Type CopyTagToType(string tagName)
static Type CopyTagToType(string tagName)
{
switch (tagName)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,8 @@ private static void AddPhysicalKeyBindingsTo(AdvancedDropdownItem parent, Keyboa
// If the key has a display name that differs from the key name, show it in the UI.
var displayName = key.m_DisplayNameFromLayout;
var keyDisplayName = key.displayName;
if (keyDisplayName.All(x => x.IsPrintable()) && string.Compare(keyDisplayName, displayName,
StringComparison.InvariantCultureIgnoreCase) != 0)
if (keyDisplayName.All(x => x.IsPrintable()) && !string.Equals(keyDisplayName, displayName,
StringComparison.InvariantCultureIgnoreCase))
displayName = $"{displayName} (Current Layout: {key.displayName})";

// For left/right modifier keys, prepend artificial combined version.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ public static void ReplaceBindingGroup(SerializedObject asset, string oldBinding
var didRename = false;
for (var n = 0; n < numGroups; ++n)
{
if (string.Compare(groupsArray[n], oldBindingGroup, StringComparison.InvariantCultureIgnoreCase) != 0)
if (!string.Equals(groupsArray[n], oldBindingGroup, StringComparison.InvariantCultureIgnoreCase))
continue;
if (string.IsNullOrEmpty(newBindingGroup))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ private static string GetPropertyTitle(SerializedProperty property)
if (property.GetParentProperty() != null && property.GetParentProperty().isArray)
propertyTitleNumeral = $" {property.GetIndexOfArrayElement()}";

if (property.displayName != null &&
property.displayName.Length > 0 &&
if (!string.IsNullOrEmpty(property.displayName) &&
(property.type == nameof(InputAction) || property.type == nameof(InputActionMap)))
{
return $"{property.displayName}{propertyTitleNumeral}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ private static void CreateNewSettingsAsset()

// Make sure it ends with .asset.
var extension = Path.GetExtension(path);
if (string.Compare(extension, ".asset", StringComparison.InvariantCultureIgnoreCase) != 0)
if (!string.Equals(extension, ".asset", StringComparison.InvariantCultureIgnoreCase))
path += ".asset";

// Create settings file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,7 @@ private static unsafe bool ShouldRecordTouch(InputControl control, double time,

// Touchscreen will record a button down and button up on a TouchControl when a tap occurs.
// We only want to record the button down, not the button up.
if (currentTouchState->isTapRelease)
return false;

return true;
return !currentTouchState->isTapRelease;
}

private unsafe void OnTouchRecorded(InputStateHistory.Record record)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,8 +475,8 @@ void AddEntry(InputAction action, PlayerInput.ActionEvent actionEvent)
var name = controlSchemes[i].name;
m_ControlSchemeOptions[i + 1] = new GUIContent(name);

if (selectedDefaultControlScheme != null && string.Compare(name, selectedDefaultControlScheme,
StringComparison.InvariantCultureIgnoreCase) == 0)
if (selectedDefaultControlScheme != null && string.Equals(name, selectedDefaultControlScheme,
StringComparison.InvariantCultureIgnoreCase))
m_SelectedDefaultControlScheme = i + 1;
}
if (m_SelectedDefaultControlScheme <= 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -740,10 +740,9 @@ private static bool IsGenerateContextMenuItemEnabled()
return false;

var assetPath = AssetDatabase.GetAssetPath(Selection.activeObject);
if (!string.IsNullOrEmpty(assetPath) && Path.GetExtension(assetPath) == ".vdf")
return true;

return false;

return !string.IsNullOrEmpty(assetPath) && Path.GetExtension(assetPath) == ".vdf";
}

////TODO: support setting class and namespace name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -713,9 +713,8 @@ private bool IsMoveAllowed(AxisEventData eventData)
if (eventSystem.currentSelectedGameObject == null)
return true;

var selectable = eventSystem.currentSelectedGameObject.GetComponent<Selectable>();

if (selectable == null)

if (!eventSystem.currentSelectedGameObject.TryGetComponent<Selectable>(out var selectable))
return true;

Selectable navigationTarget = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ private static InputActionReference GetActionReferenceFromAssets(InputActionRefe
{
foreach (var action in actions)
{
if (string.Compare(action.action.name, actionName, StringComparison.InvariantCultureIgnoreCase) == 0)
if (string.Equals(action.action.name, actionName, StringComparison.InvariantCultureIgnoreCase))
return action;
}
}
Expand All @@ -30,8 +30,7 @@ private static InputActionReference[] GetAllAssetReferencesFromAssetDatabase(Inp

var path = AssetDatabase.GetAssetPath(actions);
var assets = AssetDatabase.LoadAllAssetsAtPath(path);
return assets.Where(asset => asset is InputActionReference)
.Cast<InputActionReference>()
return assets.OfType<InputActionReference>()
.OrderBy(x => x.name)
.ToArray();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ private void InitializePlayerRoot()
{
if (m_PlayerRoot == null) return;

var inputModule = GetComponent<InputSystemUIInputModule>();
if (inputModule != null)
if (TryGetComponent<InputSystemUIInputModule>(out var inputModule))
inputModule.localMultiPlayerRoot = m_PlayerRoot;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -508,8 +508,8 @@ private bool TryFindControlScheme(string schemeName, out InputControlScheme sche
var controlSchemes = s_GlobalState.allUserData[index].actions.controlSchemes;
for (var i = 0; i < controlSchemes.Count; ++i)
{
if (string.Compare(controlSchemes[i].name, schemeName,
StringComparison.InvariantCultureIgnoreCase) == 0)
if (string.Equals(controlSchemes[i].name, schemeName,
StringComparison.InvariantCultureIgnoreCase))
{
scheme = controlSchemes[i];
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal static string OnFindLayoutForDevice(ref InputDeviceDescription descript
string matchedLayout, InputDeviceExecuteCommandDelegate executeCommandDelegate)
{
// If the device isn't a WebGL device, we're not interested.
if (string.Compare(description.interfaceName, InterfaceName, StringComparison.InvariantCultureIgnoreCase) != 0)
if (!string.Equals(description.interfaceName, InterfaceName, StringComparison.InvariantCultureIgnoreCase))
return null;

// If it was matched by the standard mapping, we don't need to fall back to generating a layout.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,26 +171,26 @@ public override string ToString()

public static bool operator==(InternedString a, string b)
{
return string.Compare(a.m_StringLowerCase, b.ToLower(CultureInfo.InvariantCulture),
StringComparison.InvariantCultureIgnoreCase) == 0;
return string.Equals(a.m_StringLowerCase, b.ToLower(CultureInfo.InvariantCulture),
StringComparison.InvariantCultureIgnoreCase);
}

public static bool operator!=(InternedString a, string b)
{
return string.Compare(a.m_StringLowerCase, b.ToLower(CultureInfo.InvariantCulture),
StringComparison.InvariantCultureIgnoreCase) != 0;
return !string.Equals(a.m_StringLowerCase, b.ToLower(CultureInfo.InvariantCulture),
StringComparison.InvariantCultureIgnoreCase);
}

public static bool operator==(string a, InternedString b)
{
return string.Compare(a.ToLower(CultureInfo.InvariantCulture), b.m_StringLowerCase,
StringComparison.InvariantCultureIgnoreCase) == 0;
return string.Equals(a.ToLower(CultureInfo.InvariantCulture), b.m_StringLowerCase,
StringComparison.InvariantCultureIgnoreCase);
}

public static bool operator!=(string a, InternedString b)
{
return string.Compare(a.ToLower(CultureInfo.InvariantCulture), b.m_StringLowerCase,
StringComparison.InvariantCultureIgnoreCase) != 0;
return !string.Equals(a.ToLower(CultureInfo.InvariantCulture), b.m_StringLowerCase,
StringComparison.InvariantCultureIgnoreCase);
}

public static bool operator<(InternedString left, InternedString right)
Expand Down