@@ -120,16 +120,15 @@ impl<'de, const BITS: usize, const LIMBS: usize> Visitor<'de> for StrVisitor<BIT
120
120
where
121
121
E : Error ,
122
122
{
123
- // ensure the string is the correct length (two characters in the string per
124
- // byte) exception: zero, for a Uint where BITS == 0
125
- if BITS == 0 {
126
- // special case, this class of ints has one member, zero.
127
- // zero is represented as "0x0" only
128
- if value != ZERO_STR {
129
- return Err ( Error :: invalid_value ( Unexpected :: Str ( value) , & self ) ) ;
130
- }
123
+ // Shortcut for common case
124
+ if value == ZERO_STR {
131
125
return Ok ( Uint :: < BITS , LIMBS > :: ZERO ) ;
132
126
}
127
+ // `ZERO_STR` is the only valid serialization of `Uint<0, 0>`, so if we
128
+ // have not shortcut, we are in an error case
129
+ if BITS == 0 {
130
+ return Err ( Error :: invalid_value ( Unexpected :: Str ( value) , & self ) ) ;
131
+ }
133
132
134
133
let value = trim_hex_prefix ( value) ;
135
134
if nbytes ( BITS ) * 2 < value. len ( ) {
@@ -150,7 +149,7 @@ impl<'de, const BITS: usize, const LIMBS: usize> Visitor<'de> for StrVisitor<BIT
150
149
}
151
150
limbs[ i] = limb;
152
151
}
153
- if BITS > 0 && limbs[ LIMBS - 1 ] > Self :: Value :: MASK {
152
+ if limbs[ LIMBS - 1 ] > Self :: Value :: MASK {
154
153
return Err ( Error :: invalid_value ( Unexpected :: Str ( value) , & self ) ) ;
155
154
}
156
155
Ok ( Uint :: from_limbs ( limbs) )
0 commit comments