Skip to content
This repository was archived by the owner on Dec 12, 2024. It is now read-only.

add sequential naming tools #838

Merged
merged 2 commits into from
Apr 11, 2024
Merged

add sequential naming tools #838

merged 2 commits into from
Apr 11, 2024

Conversation

stephen-hawley
Copy link
Contributor

Added sequential naming


public string SafeName (string name)
{
lock (nameLock) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that Interlocked.Increment will give you the same result, you'll get the lock out and the code will be more performant: https://learn.microsoft.com/en-us/dotnet/api/system.threading.interlocked.increment?view=net-8.0&redirectedfrom=MSDN#System_Threading_Interlocked_Increment_System_Int32__

Comment on lines 8 to 10
int current;
string prefix;
object nameLock = new object ();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
int current;
string prefix;
object nameLock = new object ();
int current;
string prefix;

Comment on lines 20 to 22
lock (nameLock) {
return CSSafeNaming.SafeIdentifier ($"{prefix}{name}{current++}");
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
lock (nameLock) {
return CSSafeNaming.SafeIdentifier ($"{prefix}{name}{current++}");
}
return CSSafeNaming.SafeIdentifier ($"{prefix}{name}{Interlocked.Increment(ref current)}");

@stephen-hawley stephen-hawley merged commit 404106d into main Apr 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants