-
Notifications
You must be signed in to change notification settings - Fork 16
⚡ Bolt: Optimize Helper.cs string methods #154
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
base: v4
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -74,12 +74,51 @@ public static string DecryptString(string cipherText) | |||||
|
|
||||||
| public static bool IsTheSame(string value1, string value2) | ||||||
| { | ||||||
| if (value1 == null && value2 == null) return true; | ||||||
| if (value1 != null && value2 == null) return false; | ||||||
| if (value1 == null && value2 != null) return false; | ||||||
| value1 = value1.Replace("\r\n", string.Empty).Replace("\r", string.Empty).Replace("\t", string.Empty).Replace(" ", string.Empty).Trim(); | ||||||
| value2 = value2.Replace("\r\n", string.Empty).Replace("\r", string.Empty).Replace("\t", string.Empty).Replace(" ", string.Empty).Trim(); | ||||||
| return string.Equals(value1, value2, StringComparison.OrdinalIgnoreCase); | ||||||
| if (ReferenceEquals(value1, value2)) return true; | ||||||
| if (value1 == null || value2 == null) return false; | ||||||
| if (value1.Length == 0 && value2.Length == 0) return true; | ||||||
|
|
||||||
| int i1 = 0, i2 = 0; | ||||||
| int len1 = value1.Length, len2 = value2.Length; | ||||||
|
|
||||||
| while (i1 < len1 || i2 < len2) | ||||||
| { | ||||||
| // Skip whitespace in value1 | ||||||
| while (i1 < len1 && (value1[i1] == '\r' || value1[i1] == '\n' || value1[i1] == '\t' || value1[i1] == ' ')) | ||||||
| { | ||||||
| i1++; | ||||||
| } | ||||||
|
|
||||||
| // Skip whitespace in value2 | ||||||
| while (i2 < len2 && (value2[i2] == '\r' || value2[i2] == '\n' || value2[i2] == '\t' || value2[i2] == ' ')) | ||||||
| { | ||||||
| i2++; | ||||||
| } | ||||||
|
|
||||||
| // If one string is finished, the other must also be finished (or only contain whitespace) | ||||||
| if (i1 >= len1) | ||||||
| { | ||||||
| return i2 >= len2; | ||||||
| } | ||||||
| if (i2 >= len2) | ||||||
| { | ||||||
| return i1 >= len1; | ||||||
|
||||||
| return i1 >= len1; | |
| return false; |
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 check is redundant. If both strings are empty and equal, they will typically share the same reference (both pointing to string.Empty) and will be caught by the ReferenceEquals check on line 77. If they don't share a reference but both have length 0, the main loop logic will correctly return true when both indices reach the end. Consider removing this check to simplify the code.