mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-02-22 20:42:31 +00:00
Reduce some allocations with the magic of spans etc.
This commit is contained in:
@@ -132,6 +132,36 @@ namespace MediaBrowser.Model.Entities
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets a provider id.
|
||||
/// </summary>
|
||||
/// <param name="instance">The instance.</param>
|
||||
/// <param name="name">The name.</param>
|
||||
/// <param name="value">The value.</param>
|
||||
public static void SetProviderId(this IHasProviderIds instance, ReadOnlySpan<char> name, ReadOnlySpan<char> value)
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(instance));
|
||||
}
|
||||
|
||||
// If it's null remove the key from the dictionary
|
||||
if (value.IsEmpty)
|
||||
{
|
||||
instance.ProviderIds?.Remove(name.ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
// Ensure it exists
|
||||
if (instance.ProviderIds == null)
|
||||
{
|
||||
instance.ProviderIds = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
instance.ProviderIds[name.ToString()] = value.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets a provider id.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user