Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,7 @@ public void Build(Logger logger, PackageSession packageSession, Package rootPack
// IndexMap
foreach (var asset in dep.DependencyIndexMap.Concat(dep.IndexMap))
{
if (!bundle.DependencyIndexMap.ContainsKey(asset.Key))
bundle.DependencyIndexMap.Add(asset.Key, asset.Value);
bundle.DependencyIndexMap.TryAdd(asset.Key, asset.Value);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ public static void RegisterAssembly(Assembly assembly)
if (type.GetConstructor(AssetPropertyNodeGraphConstructorSignature) is null)
throw new InvalidOperationException($"The type {type.Name} does not have a public constructor matching the expected signature: ({string.Join(", ", (IEnumerable<Type>)AssetPropertyNodeGraphConstructorSignature)})");

if (NodeGraphTypes.ContainsKey(attribute.AssetType))
if (!NodeGraphTypes.TryAdd(attribute.AssetType, type))
throw new ArgumentException($"The type {attribute.AssetType.Name} already has an associated property node graph type.");

NodeGraphTypes.Add(attribute.AssetType, type);
}

if (typeof(AssetPropertyGraphDefinition).IsAssignableFrom(type))
Expand Down
4 changes: 1 addition & 3 deletions sources/engine/Stride.Input/InputManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -783,11 +783,9 @@ private void InputDevicesOnCollectionChanged(IInputSource source, TrackingCollec
private void OnInputDeviceAdded(IInputSource source, IInputDevice device)
{
devices.Add(device);
if (devicesById.ContainsKey(device.Id))
if (!devicesById.TryAdd(device.Id, device))
throw new InvalidOperationException($"Device with Id {device.Id}({device.Name}) already registered to {devicesById[device.Id].Name}");

devicesById.Add(device.Id, device);

if (device is IKeyboardDevice)
{
RegisterKeyboard((IKeyboardDevice)device);
Expand Down
6 changes: 2 additions & 4 deletions sources/engine/Stride.Input/InputSourceBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,8 @@ protected void RegisterDevice(IInputDevice device)
/// <param name="device">The device</param>
protected void UnregisterDevice(IInputDevice device)
{
if (!Devices.ContainsKey(device.Id))
if (!Devices.Remove(device.Id))
throw new InvalidOperationException($"Input device with Id {device.Id} was not registered");

Devices.Remove(device.Id);
}
}
}
}
5 changes: 2 additions & 3 deletions sources/engine/Stride.Input/KeyboardDeviceBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,9 @@ public void HandleKeyDown(Keys key)
public void HandleKeyUp(Keys key)
{
// Prevent duplicate up events
if (!KeyRepeats.ContainsKey(key))
if (!KeyRepeats.Remove(key))
return;

KeyRepeats.Remove(key);
downKeys.Remove(key);
var keyEvent = InputEventPool<KeyEvent>.GetOrCreate(this);
keyEvent.IsDown = false;
Expand All @@ -100,4 +99,4 @@ public void HandleKeyUp(Keys key)
Events.Add(keyEvent);
}
}
}
}

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions sources/engine/Stride.UI/UIElement.Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,10 @@ public void AddHandler<T>(RoutedEvent<T> routedEvent, EventHandler<T> handler, b
if (routedEvent == null) throw new ArgumentNullException(nameof(routedEvent));
if (handler == null) throw new ArgumentNullException(nameof(handler));

if (!eventsToHandlers.ContainsKey(routedEvent))
eventsToHandlers[routedEvent] = new List<RoutedEventHandlerInfo>();
if (!eventsToHandlers.TryGetValue(routedEvent, out List<RoutedEventHandlerInfo> handlerInfos))
eventsToHandlers[routedEvent] = handlerInfos = new List<RoutedEventHandlerInfo>();

eventsToHandlers[routedEvent].Add(new RoutedEventHandlerInfo<T>(handler, handledEventsToo));
handlerInfos.Add(new RoutedEventHandlerInfo<T>(handler, handledEventsToo));
}

/// <summary>
Expand All @@ -216,10 +216,10 @@ public void RemoveHandler<T>(RoutedEvent<T> routedEvent, EventHandler<T> handler
if (routedEvent == null) throw new ArgumentNullException(nameof(routedEvent));
if (handler == null) throw new ArgumentNullException(nameof(handler));

if (!eventsToHandlers.ContainsKey(routedEvent))
if (!eventsToHandlers.TryGetValue(routedEvent, out List<RoutedEventHandlerInfo> handlerInfos))
return;

eventsToHandlers[routedEvent].Remove(new RoutedEventHandlerInfo<T>(handler));
handlerInfos.Remove(new RoutedEventHandlerInfo<T>(handler));
}

private readonly Dictionary<RoutedEvent, List<RoutedEventHandlerInfo>> eventsToHandlers = new Dictionary<RoutedEvent, List<RoutedEventHandlerInfo>>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,9 @@ public void Generate(string outputDirectory, string projectName, Guid projectGui
object oldPlatform = null;
if (fileItem.CurrentPlatform != null)
{
if (expandoOptionsAsDictionary.ContainsKey(nameof(fileItem.CurrentPlatform)))
if (expandoOptionsAsDictionary.TryGetValue(nameof(fileItem.CurrentPlatform), out object currentPlatform))
{
oldPlatform = expandoOptionsAsDictionary[nameof(fileItem.CurrentPlatform)];
oldPlatform = currentPlatform;
}
expandoOptionsAsDictionary[nameof(fileItem.CurrentPlatform)] = fileItem.CurrentPlatform;
}
Expand Down
5 changes: 1 addition & 4 deletions sources/tools/Stride.FreeImage/FreeImageWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3827,10 +3827,7 @@ public static bool FindNextMetadata(FIMETADATA mdhandle, out MetadataTag tag)
/// <param name="mdhandle">The handle to close.</param>
public static void FindCloseMetadata(FIMETADATA mdhandle)
{
if (metaDataSearchHandler.ContainsKey(mdhandle))
{
metaDataSearchHandler.Remove(mdhandle);
}
metaDataSearchHandler.Remove(mdhandle);
FindCloseMetadata_(mdhandle);
}

Expand Down
Loading