-
Notifications
You must be signed in to change notification settings - Fork 927
Fast React ID Generator #528
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
Fast React ID Generator #528
Conversation
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.
This seems OK to me. @dustinsoftware what do you think?
src/React.Core/ReactIdGenerator.cs
Outdated
var id = Interlocked.Increment(ref _random); | ||
|
||
//reactPrefix.Length == 6 | ||
chars[6] = _encode32Chars[(int)(id >> 60) & 31]; |
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.
There's a lot of magic numbers in this code. It'd be good to pull these out as constants and add comments explaining what they're doing.
src/React.Core/ReactIdGenerator.cs
Outdated
/// <summary> | ||
/// Extension methods relating to GUIDs. | ||
/// </summary> | ||
public static class ReactIdGenerator |
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.
Would be good to add an interface for this, and use the dependency injection framework to inject it into ReactComponent
. That way, anyone can swap out the implementation if they want to (eg. if they want the old one back).
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.
(see AssemblyRegistration.cs
, use .AsSingleton()
)
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.
Nice idea, i can inject it to ReactEnvironment and create property IReactIdGenerator (like IBabel) and call it from constructor in ReactComponent like "environment.ReactIdGenerator.Generate(...)"
src/React.Core/ReactIdGenerator.cs
Outdated
var chars = _chars; | ||
if (chars == null) | ||
{ | ||
_chars = chars = new char[19]; |
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.
Why 19?
src/React.Core/ReactIdGenerator.cs
Outdated
chars[17] = _encode32Chars[(int)(id >> 5) & 31]; | ||
chars[18] = _encode32Chars[(int)id & 31]; | ||
|
||
return new string(chars, 0, 19); |
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.
Pull out 19
as a constant
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.
ok!, const will be inlined without overhead 👍
You can pass it in the constructor for ReactComponent rather than adding a
property to ReactEnvironment
Sent from my phone.
…On Mon, Apr 9, 2018, 7:13 AM Daniil Sokolyuk ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In src/React.Core/ReactIdGenerator.cs
<#528 (comment)>:
> + * All rights reserved.
+ *
+ * This source code is licensed under the BSD-style license found in the
+ * LICENSE file in the root directory of this source tree. An additional grant
+ * of patent rights can be found in the PATENTS file in the same directory.
+ */
+
+using System;
+using System.Threading;
+
+namespace React
+{
+ /// <summary>
+ /// Extension methods relating to GUIDs.
+ /// </summary>
+ public static class ReactIdGenerator
Nice idea, i can inject it to IReactEnvironment and create property
IReactIdGenerator (like IBabel) and call it from constructor like
"environment.ReactIdGenerator.Generate(...)"
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#528 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAFnHbQsP0g0FVqr52UqGGL4msV_r2fsks5tm2yjgaJpZM4TLl08>
.
|
Completed. |
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.
Thanks! Looks good.
{ | ||
public class GuidExtensionsTests | ||
public interface IReactIdGenerator |
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.
Ugh, sorry. Missed this one. There is no XML comment for this type which is generating a warning at build time.
Fast React ID Generator