Skip to content

Commit ac44a38

Browse files
authored
refactor: remove code duplication in chunk size parsing (#219)
The logic for uppercase letters and lowercase letters can be merged.
1 parent 4b902ec commit ac44a38

File tree

1 file changed

+2
-13
lines changed

1 file changed

+2
-13
lines changed

src/lib.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,7 +1287,7 @@ pub fn parse_chunk_size(buf: &[u8])
12871287
size *= RADIX;
12881288
size += (b - b'0') as u64;
12891289
},
1290-
b'a' ..= b'f' if in_chunk_size => {
1290+
b'a' ..= b'f' | b'A' ..= b'F' if in_chunk_size => {
12911291
if count > 15 {
12921292
return Err(InvalidChunkSize);
12931293
}
@@ -1296,18 +1296,7 @@ pub fn parse_chunk_size(buf: &[u8])
12961296
return Err(InvalidChunkSize);
12971297
}
12981298
size *= RADIX;
1299-
size += (b + 10 - b'a') as u64;
1300-
}
1301-
b'A' ..= b'F' if in_chunk_size => {
1302-
if count > 15 {
1303-
return Err(InvalidChunkSize);
1304-
}
1305-
count += 1;
1306-
if cfg!(debug_assertions) && size > (u64::MAX / RADIX) {
1307-
return Err(InvalidChunkSize);
1308-
}
1309-
size *= RADIX;
1310-
size += (b + 10 - b'A') as u64;
1299+
size += ((b | 0x20) + 10 - b'a') as u64;
13111300
}
13121301
b'\r' => {
13131302
match next!(bytes) {

0 commit comments

Comments
 (0)