Skip to content
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

Use reference-counted strings in dns::Name #2509

Merged
merged 1 commit into from
Nov 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions linkerd/dns/name/src/name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

use std::{fmt, ops::Deref};
use std::{fmt, ops::Deref, sync::Arc};
use thiserror::Error;

/// A DNS Name suitable for use in the TLS Server Name Indication (SNI)
Expand All @@ -30,7 +30,7 @@ use thiserror::Error;
///
/// [RFC 5280 Section 7.2]: https://tools.ietf.org/html/rfc5280#section-7.
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
pub struct Name(String);
pub struct Name(Arc<str>);

/// A reference to a DNS Name suitable for use in the TLS Server Name Indication
/// (SNI) extension and/or for use as the reference hostname for which to verify
Expand Down Expand Up @@ -60,12 +60,12 @@ impl Name {

#[inline]
pub fn as_ref(&self) -> NameRef<'_> {
NameRef(self.0.as_str())
NameRef(&self.0)
}

#[inline]
pub fn as_str(&self) -> &str {
self.0.as_str()
&self.0
}

#[inline]
Expand Down Expand Up @@ -104,7 +104,7 @@ impl Deref for Name {

#[inline]
fn deref(&self) -> &str {
self.0.as_str()
&self.0
}
}

Expand All @@ -130,7 +130,7 @@ impl<'a> NameRef<'a> {
pub fn to_owned(self) -> Name {
// NameRef is already guaranteed to be valid ASCII, which is a
// subset of UTF-8.
Name(self.as_str().to_ascii_lowercase())
Name(self.as_str().to_ascii_lowercase().into())
}

#[inline]
Expand Down