Skip to content

Commit dda33b7

Browse files
committed
Avoid string allocation to get length of port
1 parent 74b8694 commit dda33b7

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

url/src/slicing.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ impl Url {
152152
Position::AfterPort => {
153153
if let Some(port) = self.port {
154154
debug_assert!(self.byte_at(self.host_end) == b':');
155-
self.host_end as usize + ":".len() + port.to_string().len()
155+
let port_length = port.checked_ilog10().unwrap_or(0) as usize + 1;
156+
self.host_end as usize + ":".len() + port_length
156157
} else {
157158
self.host_end as usize
158159
}

0 commit comments

Comments
 (0)