-
Notifications
You must be signed in to change notification settings - Fork 401
Store HumanReadableName
s in-object rather than on the heap
#3733
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
I've assigned @valentinewallace as a reviewer! |
Since the full encoded domain name of an HRN cannot exceed the maximum length of a DNS name (255 octets), there's not a lot of reason to store the `user` and `domain` parts of an HRN on the heap via two `String`s. Instead, here, we store one byte array with the maximum size of both labels as well as the length of the `user` and `domain` parts. Because we're now avoiding heap allocations this also implies making `HumanReadableName::new` take the `user` and `domain` parts by reference as `&str`s, rather than by value as `String`s.
7f610cb
to
4583457
Compare
🔔 1st Reminder Hey @valentinewallace! This PR has been waiting for your review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically LGTM
|
||
/// Check if the chars in `s` are allowed to be included in a hostname. | ||
pub(crate) fn str_chars_allowed(s: &str) -> bool { | ||
s.chars().all(|c| c.is_ascii_alphanumeric() || c == '.' || c == '_' || c == '-') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we call this method from Hostname::str_is_valid_hostname
or vice versa?
Ok(user) => user, | ||
Err(_) => return Err(DecodeError::InvalidValue), | ||
}; | ||
|
||
let mut domain_bytes = [0; 255]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason to not use the 231
value mentioned above?
👋 The first review has been submitted! Do you think this PR is ready for a second reviewer? If so, click here to assign a second reviewer. |
Since the full encoded domain name of an HRN cannot exceed the maximum length of a DNS name (255 octets), there's not a lot of reason to store the
user
anddomain
parts of an HRN on the heap via twoString
s.Instead, here, we store one byte array with the maximum size of both labels as well as the length of the
user
anddomain
parts.Because we're now avoiding heap allocations this also implies making
HumanReadableName::new
take theuser
anddomain
parts by reference as&str
s, rather than by value asString
s.