Optimize TargetTriple: Use Cow<'static, str> (#1161)

instead of `CompactString` since `target_lexicon::{OperatingSystem,
Architecture, Environment}::into_str()` will return a `&'static str`
most of the time.

Also updated `SUPPORT.md`.

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2023-06-21 20:05:19 +10:00 committed by GitHub
parent abecd9ae14
commit 138112cd6e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 13 deletions

View file

@ -30,7 +30,7 @@ once_cell = "1.18.0"
semver = { version = "1.0.17", features = ["serde"] }
serde = { version = "1.0.163", features = ["derive"] }
strum = "0.25.0"
target-lexicon = { version = "0.12.7", features = ["std"] }
target-lexicon = { version = "0.12.8", features = ["std"] }
tempfile = "3.5.0"
thiserror = "1.0.40"
# parking_lot for `tokio::sync::OnceCell::const_new`

View file

@ -7,11 +7,9 @@ use crate::{errors::BinstallError, helpers::is_universal_macos};
#[derive(Clone, Debug)]
pub struct TargetTriple {
// TODO: Once https://github.com/bytecodealliance/target-lexicon/pull/90
// lands, consider replacing use of CompactString with `Cow<'_, str>`.
pub target_family: CompactString,
pub target_arch: CompactString,
pub target_libc: CompactString,
pub target_family: Cow<'static, str>,
pub target_arch: Cow<'static, str>,
pub target_libc: Cow<'static, str>,
pub target_vendor: CompactString,
}
@ -28,13 +26,13 @@ impl FromStr for TargetTriple {
let triple = Triple::from_str(s)?;
Ok(Self {
target_family: triple.operating_system.to_compact_string(),
target_family: triple.operating_system.into_str(),
target_arch: if is_universal_macos {
"universal".to_compact_string()
Cow::Borrowed("universal")
} else {
triple.architecture.to_compact_string()
triple.architecture.into_str()
},
target_libc: triple.environment.to_compact_string(),
target_libc: triple.environment.into_str(),
target_vendor: triple.vendor.to_compact_string(),
})
}