-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial POC commit for adding ReadOnlyMemory overloads to StringSet o… #2221
base: main
Are you sure you want to change the base?
Conversation
/// <remarks> | ||
/// <seealso href="https://redis.io/commands/mset"/>, | ||
/// <seealso href="https://redis.io/commands/msetnx"/> | ||
/// </remarks> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
possibly worth a warning about FireAndForget being dangerous here if the ReadOnlyMemory is going to be recycled/reused?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely seems wise, thank you. I'll add warnings for all of the new methods taking ReadOnlyMemory. If the approach looks good overall, I'll continue expanding the surface area.
|
||
for (int i = 0; i < outer.Length; ++i) | ||
{ | ||
inner[i] = ToInner(outer.Span[i]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Accessing .Span is relatively expensive; this should be done outside the loop and resused.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ++i is very unusual for C#, note
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, thanks! I'll make the changes to cache all call sites for .Span.
The ++i was copied from line 801 of the diff. I assumed that was intentional and copied it here. Is that an incorrect usage?
Not wrong, just atypical. Consistency/copy-paste is a valid reason here!
…On Sat, 27 Aug 2022, 00:09 Stabzs, ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In src/StackExchange.Redis/KeyspaceIsolation/WrapperBase.cs
<#2221 (comment)>
:
> @@ -804,6 +807,25 @@ internal WrapperBase(TInner inner, byte[] keyPrefix)
}
}
+ protected ReadOnlyMemory<KeyValuePair<RedisKey, RedisValue>> ToInner(ReadOnlyMemory<KeyValuePair<RedisKey, RedisValue>> outer)
+ {
+ if (outer.Length == 0)
+ {
+ return outer;
+ }
+ else
+ {
+ KeyValuePair<RedisKey, RedisValue>[] inner = new KeyValuePair<RedisKey, RedisValue>[outer.Length];
+
+ for (int i = 0; i < outer.Length; ++i)
+ {
+ inner[i] = ToInner(outer.Span[i]);
I'll make the changes to cache all call sites for .Span.
The ++i was copied from line 801 of the diff. I assumed that was
intentional and copied it here. Is that an incorrect usage?
—
Reply to this email directly, view it on GitHub
<#2221 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAEHMDLPK2KLL5VTQUUT43V3FFC7ANCNFSM566WTIXA>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
…perations.