@@ -83,15 +83,7 @@ public Task<bool> RemoveAsync(string key, CommandFlags flag = CommandFlags.None)
83
83
/// <inheritdoc/>
84
84
public Task < long > RemoveAllAsync ( string [ ] keys , CommandFlags flag = CommandFlags . None )
85
85
{
86
- var redisKeys = new RedisKey [ keys . Length ] ;
87
-
88
- ref var searchSpace = ref MemoryMarshal . GetReference ( keys . AsSpan ( ) ) ;
89
-
90
- for ( var i = 0 ; i < keys . Length ; i ++ )
91
- {
92
- ref var key = ref Unsafe . Add ( ref searchSpace , i ) ;
93
- redisKeys [ i ] = ( RedisKey ) key ;
94
- }
86
+ var redisKeys = keys . ToFastArray ( key => ( RedisKey ) key ) ;
95
87
96
88
return Database . KeyDeleteAsync ( redisKeys , flag ) ;
97
89
}
@@ -334,13 +326,12 @@ public Task<long> SetAddAllAsync<T>(string key, CommandFlags flag = CommandFlags
334
326
if ( items . Any ( item => item == null ) )
335
327
throw new ArgumentException ( "items cannot contains any null item." , nameof ( items ) ) ;
336
328
329
+ var values = items . ToFastArray ( item => ( RedisValue ) Serializer . Serialize ( item ) ) ;
330
+
337
331
return Database
338
332
. SetAddAsync (
339
333
key ,
340
- items
341
- . Select ( item => Serializer . Serialize ( item ) )
342
- . Select ( x => ( RedisValue ) x )
343
- . ToArray ( ) ,
334
+ values ,
344
335
flag ) ;
345
336
}
346
337
@@ -370,17 +361,17 @@ public Task<long> SetRemoveAllAsync<T>(string key, CommandFlags flag = CommandFl
370
361
if ( items . Any ( item => item == null ) )
371
362
throw new ArgumentException ( "items cannot contains any null item." , nameof ( items ) ) ;
372
363
373
- return Database . SetRemoveAsync ( key , items
374
- . Select ( item => Serializer . Serialize ( item ) )
375
- . Select ( x => ( RedisValue ) x )
376
- . ToArray ( ) , flag ) ;
364
+ var values = items . ToFastArray ( item => ( RedisValue ) Serializer . Serialize ( item ) ) ;
365
+
366
+ return Database . SetRemoveAsync ( key , values , flag ) ;
377
367
}
378
368
379
369
/// <inheritdoc/>
380
370
public async Task < string [ ] > SetMemberAsync ( string memberName , CommandFlags flag = CommandFlags . None )
381
371
{
382
372
var members = await Database . SetMembersAsync ( memberName , flag ) . ConfigureAwait ( false ) ;
383
- return members . Select ( x => x . ToString ( ) ) . ToArray ( ) ;
373
+
374
+ return members . ToFastArray ( x => x . ToString ( ) ) ;
384
375
}
385
376
386
377
/// <inheritdoc/>
@@ -489,13 +480,7 @@ private static Dictionary<string, string> ParseInfo(string info)
489
480
490
481
var result = new Dictionary < string , string > ( ) ;
491
482
492
- ref var searchSpace = ref MemoryMarshal . GetReference ( data . AsSpan ( ) ) ;
493
-
494
- for ( var i = 0 ; i < data . Length ; i ++ )
495
- {
496
- ref var x = ref Unsafe . Add ( ref searchSpace , i ) ;
497
- result . TryAdd ( x . Key , x . InfoValue ) ;
498
- }
483
+ data . FastIteration ( ( x , _ ) => result . TryAdd ( x . Key , x . InfoValue ) ) ;
499
484
500
485
return result ;
501
486
}
0 commit comments