Skip to content

Commit

Permalink
perf(fastconvert): Replace the switch by a calculation for 1-digit st…
Browse files Browse the repository at this point in the history
…ring conversion.
  • Loading branch information
carldebilly committed Nov 13, 2020
1 parent 9640213 commit 87832b0
Showing 1 changed file with 9 additions and 90 deletions.
99 changes: 9 additions & 90 deletions src/Uno.UI/DataBinding/BindingPropertyHelper.FastConvert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -647,37 +647,10 @@ private static bool FastStringToDoubleConvert(Type outputType, string input, ref
{
// Fast path for one digit string-to-double.
// Often use in VisualStateManager to set double values (like opacity) to zero or one...
switch (input[0])
var c = input[0];
if (c >= '0' && c <= '9')
{
case '0':
output = 0d;
return true;
case '1':
output = 1d;
return true;
case '2':
output = 2d;
return true;
case '3':
output = 3d;
return true;
case '4':
output = 4d;
return true;
case '5':
output = 5d;
return true;
case '6':
output = 6d;
return true;
case '7':
output = 7d;
return true;
case '8':
output = 8d;
return true;
case '9':
output = 9d;
output= (double)(c - '0');
return true;
}
}
Expand Down Expand Up @@ -734,37 +707,10 @@ private static bool FastStringToSingleConvert(Type outputType, string input, ref
if (input.Length == 1)
{
// Fast path for one digit string-to-float
switch (input[0])
var c = input[0];
if (c >= '0' && c <= '9')
{
case '0':
output = 0f;
return true;
case '1':
output = 1f;
return true;
case '2':
output = 2f;
return true;
case '3':
output = 3f;
return true;
case '4':
output = 4f;
return true;
case '5':
output = 5f;
return true;
case '6':
output = 6f;
return true;
case '7':
output = 7f;
return true;
case '8':
output = 8f;
return true;
case '9':
output = 9f;
output = (float)(c - '0');
return true;
}
}
Expand Down Expand Up @@ -814,37 +760,10 @@ private static bool FastStringToIntegerConvert(Type outputType, string input, re
if (input.Length == 1)
{
// Fast path for one digit string-to-float
switch (input[0])
var c = input[0];
if (c >= '0' && c <= '9')
{
case '0':
output = 0;
return true;
case '1':
output = 1;
return true;
case '2':
output = 2;
return true;
case '3':
output = 3;
return true;
case '4':
output = 4;
return true;
case '5':
output = 5;
return true;
case '6':
output = 6;
return true;
case '7':
output = 7;
return true;
case '8':
output = 8;
return true;
case '9':
output = 9;
output = (int)(c - '0');
return true;
}
}
Expand Down

0 comments on commit 87832b0

Please sign in to comment.