6
6
using System . Collections . Generic ;
7
7
using System . Linq . Expressions ;
8
8
using System . Reflection ;
9
+ using System . Runtime . CompilerServices ;
9
10
10
11
namespace Nethermind . Core . Collections
11
12
{
@@ -15,13 +16,49 @@ public static class CollectionExtensions
15
16
16
17
public static void AddRange < T > ( this ICollection < T > list , IEnumerable < T > items )
17
18
{
18
- foreach ( T item in items )
19
+ if ( items is T [ ] array )
19
20
{
20
- list . Add ( item ) ;
21
+ list . AddRange ( array ) ;
22
+ }
23
+ else if ( items is IList < T > listItems )
24
+ {
25
+ list . AddRange ( listItems ) ;
26
+ }
27
+ else if ( items is IReadOnlyList < T > readOnlyList )
28
+ {
29
+ list . AddRange ( readOnlyList ) ;
30
+ }
31
+ else
32
+ {
33
+ foreach ( T item in items )
34
+ {
35
+ list . Add ( item ) ;
36
+ }
37
+ }
38
+ }
39
+
40
+ [ OverloadResolutionPriority ( 2 ) ]
41
+ public static void AddRange < T > ( this ICollection < T > list , IList < T > items )
42
+ {
43
+ int count = items . Count ;
44
+ for ( int index = 0 ; index < count ; index ++ )
45
+ {
46
+ list . Add ( items [ index ] ) ;
47
+ }
48
+ }
49
+
50
+ [ OverloadResolutionPriority ( 1 ) ]
51
+ public static void AddRange < T > ( this ICollection < T > list , IReadOnlyList < T > items )
52
+ {
53
+ int count = items . Count ;
54
+ for ( int index = 0 ; index < count ; index ++ )
55
+ {
56
+ list . Add ( items [ index ] ) ;
21
57
}
22
58
}
23
59
24
- public static void AddRange < T > ( this ICollection < T > list , params T [ ] items )
60
+ [ OverloadResolutionPriority ( 3 ) ]
61
+ public static void AddRange < T > ( this ICollection < T > list , T [ ] items )
25
62
{
26
63
for ( int index = 0 ; index < items . Length ; index ++ )
27
64
{
0 commit comments