diff options
| author | cvium <clausvium@gmail.com> | 2021-04-30 15:09:36 +0200 |
|---|---|---|
| committer | cvium <clausvium@gmail.com> | 2021-04-30 15:09:36 +0200 |
| commit | 608cba817c54df60959079719bafca4d7d54269a (patch) | |
| tree | db024902a82c5ec64ffc88c0827d4f891cf45983 /MediaBrowser.Model/Entities | |
| parent | eeb5d4bd1e63ad89f599fd52a79b3c80ed8f8ad1 (diff) | |
Reduce some allocations with the magic of spans etc.
Diffstat (limited to 'MediaBrowser.Model/Entities')
| -rw-r--r-- | MediaBrowser.Model/Entities/ProviderIdsExtensions.cs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/MediaBrowser.Model/Entities/ProviderIdsExtensions.cs b/MediaBrowser.Model/Entities/ProviderIdsExtensions.cs index 09d14dc6a..bc14da7f2 100644 --- a/MediaBrowser.Model/Entities/ProviderIdsExtensions.cs +++ b/MediaBrowser.Model/Entities/ProviderIdsExtensions.cs @@ -136,6 +136,36 @@ namespace MediaBrowser.Model.Entities /// 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> + /// <param name="instance">The instance.</param> /// <param name="provider">The provider.</param> /// <param name="value">The value.</param> public static void SetProviderId(this IHasProviderIds instance, MetadataProvider provider, string value) |
