Skip to content
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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

DEATHB4DEFEAT
Copy link
Member

Description

Adds a new Type for Prototypes to inherit instead of IPrototype with standard localization formats and lambda shortcuts to them.


@DEATHB4DEFEAT DEATHB4DEFEAT added Priority: 3-Medium Needs to be resolved at some point Size: 5-Very Small For especially small issues/PRs Type: Codebase An issue with the codebase labels Aug 18, 2024
@github-actions github-actions bot added Status: Needs Review Someone please review this Changes: C# Changes any cs files labels Aug 18, 2024
@DEATHB4DEFEAT DEATHB4DEFEAT mentioned this pull request Aug 18, 2024
11 tasks
Content.Shared/Prototypes/LocalizedPrototype.cs Outdated Show resolved Hide resolved
Content.Shared/Prototypes/LocalizedPrototype.cs Outdated Show resolved Hide resolved
Comment on lines +14 to +16
public string NameLoc => ToLocalizationString("name");
/// <summary>The localized string for the name of prototype</summary>
public string Name => Loc.GetString(NameLoc);
Copy link
Contributor

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()));
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changes: C# Changes any cs files Priority: 3-Medium Needs to be resolved at some point Size: 5-Very Small For especially small issues/PRs Status: Needs Review Someone please review this Type: Codebase An issue with the codebase
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants