-
Notifications
You must be signed in to change notification settings - Fork 966
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
Improve PrependArticleSuffix perf #1419
Conversation
src/Humanizer/ArticlePrefixSort.cs
Outdated
@@ -48,60 +48,68 @@ public static string[] PrependArticleSuffix(string[] appended) | |||
{ | |||
var inserted = new string[appended.Length]; | |||
|
|||
// ReSharper disable InconsistentNaming | |||
var The = "The".AsSpan(); |
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
could be _The[1..]
, etc.
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.
Actually it seems that The
and others are not needed at all.
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.
good idea. i applied the _The[1..]
are not needed at all.
they are used. we could use _The[1..]
but the variables make the below code a little more readable
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.
I see that they are used:
if (append.EndsWith(The))
{
var suffix = append[append.IndexOf(_The, StringComparison.CurrentCulture)..];
inserted[i] = ToOriginalFormat(append, suffix);
}
But would not be that just an equivalent of the following?
if (append.EndsWith(_The))
{
var suffix = append[append.IndexOf(_The, StringComparison.CurrentCulture)..];
inserted[i] = ToOriginalFormat(append, suffix);
}
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.
Also... I think the code is not entirely correct:
append.IndexOf(_The, StringComparison.CurrentCulture)
will find a first index of " The"
instead of last. I think something like "The General Theory of Relativity" would be completely destroyed by this process.
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.
Expected: ["The General Theory of Relativity"]
Actual: ["Theory of Relativity The General"]
suffix = append.Substring(append.IndexOf(" The", StringComparison.CurrentCulture)); | ||
original = ToOriginalFormat(appended, suffix, i); | ||
inserted[i] = original; | ||
var suffix = append[append.IndexOf(_The, StringComparison.CurrentCulture)..]; |
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.
suffix
here is known to be" The"
. It does not make sense to try to extract it from the string.append.IndexOf(_The, StringComparison.CurrentCulture)
should beappend.LastIndexOf(_The, StringComparison.CurrentCulture)
. Which is known to beappend.Length - " The".Length
ToOriginalFormat(append, suffix)
again does the same operationappend.IndexOf(suffix, StringComparison.CurrentCulture)
v2.14.1
v3.0.0