mirror of
https://fastgit.cc/github.com/sourcegit-scm/sourcegit
synced 2026-04-23 10:22:13 +08:00
enhance: improve NumericSort.Compare performance
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
@@ -21,6 +21,10 @@
|
||||
int loc2 = 0;
|
||||
|
||||
bool isDigit1 = char.IsDigit(c1);
|
||||
bool isDigit2 = char.IsDigit(c2);
|
||||
if (isDigit1 != isDigit2)
|
||||
return c1.CompareTo(c2);
|
||||
|
||||
do
|
||||
{
|
||||
tmp1[loc1] = c1;
|
||||
@@ -33,7 +37,6 @@
|
||||
break;
|
||||
} while (char.IsDigit(c1) == isDigit1);
|
||||
|
||||
bool isDigit2 = char.IsDigit(c2);
|
||||
do
|
||||
{
|
||||
tmp2[loc2] = c2;
|
||||
@@ -49,7 +52,7 @@
|
||||
string sub1 = new string(tmp1, 0, loc1);
|
||||
string sub2 = new string(tmp2, 0, loc2);
|
||||
int result;
|
||||
if (isDigit1 && isDigit2)
|
||||
if (isDigit1)
|
||||
result = loc1 == loc2 ? string.CompareOrdinal(sub1, sub2) : loc1 - loc2;
|
||||
else
|
||||
result = string.CompareOrdinal(sub1, sub2);
|
||||
|
||||
Reference in New Issue
Block a user