Skip to content

Commit 1689484

Browse files
authored
[OpAmp.Client] Drop reference to System.Collections.Immutable (#3154)
1 parent fabb87f commit 1689484

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

src/OpenTelemetry.OpAmp.Client/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## Unreleased
44

5+
* Drop reference to `System.Collections.Immutable`.
6+
([#3154](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/3154))
7+
58
## 0.1.0-alpha.1
69

710
Released 2025-Sep-23

src/OpenTelemetry.OpAmp.Client/Internal/FrameProcessor.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
using System.Buffers;
55
using System.Collections.Concurrent;
6-
using System.Collections.Immutable;
76
using OpAmp.Proto.V1;
87
using OpenTelemetry.Internal;
98
using OpenTelemetry.OpAmp.Client.Internal.Listeners;
@@ -14,7 +13,7 @@ namespace OpenTelemetry.OpAmp.Client.Internal;
1413

1514
internal sealed class FrameProcessor
1615
{
17-
private readonly ConcurrentDictionary<Type, ImmutableList<IOpAmpListener>> listeners = [];
16+
private readonly ConcurrentDictionary<Type, IReadOnlyList<IOpAmpListener>> listeners = [];
1817

1918
public void Subscribe<T>(IOpAmpListener<T> listener)
2019
where T : IOpAmpMessage
@@ -25,7 +24,13 @@ public void Subscribe<T>(IOpAmpListener<T> listener)
2524
this.listeners.AddOrUpdate(
2625
typeof(T),
2726
_ => [listener],
28-
(_, list) => list.Add(listener));
27+
(_, list) =>
28+
{
29+
var newList = new List<IOpAmpListener>(list.Count + 1);
30+
newList.AddRange(list);
31+
newList.Add(listener);
32+
return newList;
33+
});
2934
}
3035

3136
public void Unsubscribe<T>(IOpAmpListener<T> listener)
@@ -35,15 +40,15 @@ public void Unsubscribe<T>(IOpAmpListener<T> listener)
3540

3641
this.listeners.AddOrUpdate(
3742
typeof(T),
38-
_ => ImmutableList<IOpAmpListener>.Empty,
43+
_ => [],
3944
(_, list) =>
4045
{
4146
if (list.Count == 1 && list[0] == listener)
4247
{
43-
return ImmutableList<IOpAmpListener>.Empty;
48+
return [];
4449
}
4550

46-
return list.Remove(listener);
51+
return list.Where(x => x != listener).ToList();
4752
});
4853
}
4954

src/OpenTelemetry.OpAmp.Client/OpenTelemetry.OpAmp.Client.csproj

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@
2424
<!-- .NET Framework supporting packages -->
2525
<ItemGroup Condition="'$(TargetFramework)' == '$(NetFrameworkMinimumSupportedVersion)'">
2626
<PackageReference Include="System.Net.Http" Version="4.3.4" />
27-
<PackageReference Include="System.Collections.Immutable" Version="8.0.0" />
28-
</ItemGroup>
29-
30-
<!-- .NET Standard supporting packages -->
31-
<ItemGroup Condition="'$(TargetFramework)' == '$(NetStandardMinimumSupportedVersion)'">
32-
<PackageReference Include="System.Collections.Immutable" Version="8.0.0" />
3327
</ItemGroup>
3428

3529
<ItemGroup>

0 commit comments

Comments
 (0)