-
Notifications
You must be signed in to change notification settings - Fork 146
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
Add LocalizedPrototype Type #747
Add LocalizedPrototype Type #747
Conversation
public string NameLoc => ToLocalizationString("name"); | ||
/// <summary>The localized string for the name of prototype</summary> | ||
public string Name => Loc.GetString(NameLoc); |
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 recalculates NameLoc every time either of those properties is accessed, which is bad. It should be cached and only calculated once (perhaps as a deserialization hook, or a lazily evaluated/cached property?)
// Lowercase the first letter | ||
type = char.ToLowerInvariant(type[0]) + type[1..]; | ||
// Replace every uppercase letter with a dash and the lowercase letter | ||
type = type.Aggregate("", (current, c) => current + (char.IsUpper(c) ? "-" + char.ToLowerInvariant(c) : c.ToString())); |
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 performs n
string concatenations, each concatenation having a cost of n
itself, resulting in an O(n²)
operation. This should use a StringBuilder instead. Considering that this function will be called hundreds or thousands of times, performance matters here.
This PR is approved but is it still going forward? |
Description
Adds a new Type for Prototypes to inherit instead of IPrototype with standard localization formats and lambda shortcuts to them.