mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-25 21:07:20 -08:00
enhance: improve NumericSort.Compare
performance
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
parent
651d313496
commit
489b57858f
1 changed files with 5 additions and 2 deletions
|
@ -21,6 +21,10 @@
|
||||||
int loc2 = 0;
|
int loc2 = 0;
|
||||||
|
|
||||||
bool isDigit1 = char.IsDigit(c1);
|
bool isDigit1 = char.IsDigit(c1);
|
||||||
|
bool isDigit2 = char.IsDigit(c2);
|
||||||
|
if (isDigit1 != isDigit2)
|
||||||
|
return c1.CompareTo(c2);
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
tmp1[loc1] = c1;
|
tmp1[loc1] = c1;
|
||||||
|
@ -33,7 +37,6 @@
|
||||||
break;
|
break;
|
||||||
} while (char.IsDigit(c1) == isDigit1);
|
} while (char.IsDigit(c1) == isDigit1);
|
||||||
|
|
||||||
bool isDigit2 = char.IsDigit(c2);
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
tmp2[loc2] = c2;
|
tmp2[loc2] = c2;
|
||||||
|
@ -49,7 +52,7 @@
|
||||||
string sub1 = new string(tmp1, 0, loc1);
|
string sub1 = new string(tmp1, 0, loc1);
|
||||||
string sub2 = new string(tmp2, 0, loc2);
|
string sub2 = new string(tmp2, 0, loc2);
|
||||||
int result;
|
int result;
|
||||||
if (isDigit1 && isDigit2)
|
if (isDigit1)
|
||||||
result = loc1 == loc2 ? string.CompareOrdinal(sub1, sub2) : loc1 - loc2;
|
result = loc1 == loc2 ? string.CompareOrdinal(sub1, sub2) : loc1 - loc2;
|
||||||
else
|
else
|
||||||
result = string.CompareOrdinal(sub1, sub2);
|
result = string.CompareOrdinal(sub1, sub2);
|
||||||
|
|
Loading…
Reference in a new issue