File tree Expand file tree Collapse file tree 1 file changed +13
-11
lines changed
PhpSerializerNET/Deserialization Expand file tree Collapse file tree 1 file changed +13
-11
lines changed Original file line number Diff line number Diff line change @@ -38,19 +38,21 @@ internal double GetDouble(ReadOnlySpan<byte> input) {
38
38
internal int GetInt ( ReadOnlySpan < byte > input ) {
39
39
// All the PHP integers we deal with here can only be the number characters and an optional "-".
40
40
// See also the Validator code.
41
- // 'long.Parse()' has to take into account that we can skip here, making this manual approach faster.
41
+ // 'long.Parse()' has to make considerations that we can skip here, making this manual approach faster.
42
42
var span = input . Slice ( this . Start , this . Length ) ;
43
- int i = 0 ;
44
- bool isNegative = false ;
45
- if ( span [ 0 ] == '-' ) {
46
- i ++ ;
47
- isNegative = true ;
43
+ if ( span [ 0 ] == ( byte ) '-' ) {
44
+ int result = span [ 1 ] - 48 ;
45
+ for ( int i = 2 ; i < span . Length ; i ++ ) {
46
+ result = result * 10 + ( span [ i ] - 48 ) ;
47
+ }
48
+ return result * - 1 ;
49
+ } else {
50
+ int result = span [ 0 ] - 48 ;
51
+ for ( int i = 1 ; i < span . Length ; i ++ ) {
52
+ result = result * 10 + ( span [ i ] - 48 ) ;
53
+ }
54
+ return result ;
48
55
}
49
- int result = 0 ;
50
- for ( ; i < span . Length ; i ++ ) {
51
- result = result * 10 + ( span [ i ] - 48 ) ;
52
- }
53
- return isNegative ? result * - 1 : result ;
54
56
}
55
57
56
58
internal string GetString ( ReadOnlySpan < byte > input , Encoding inputEncoding ) {
You can’t perform that action at this time.
0 commit comments