diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2023-03-23 23:27:58 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-23 23:27:58 +0100 |
commit | 275dee60e71225a9c6c4b3b4ea7ffe4c6ecb4d87 (patch) | |
tree | 13ed3ab7e825a81085e8dcc5efeee417416b86cf /cli/version.rs | |
parent | edab8f2fd48efddc19eb0032955fee4b5dbf76e6 (diff) |
refactor: make version and user_agent &'static str (#18400)
These caused a bunch of unnecessary allocations on each startup.
Diffstat (limited to 'cli/version.rs')
-rw-r--r-- | cli/version.rs | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/cli/version.rs b/cli/version.rs index 88dc9ffc7..f13baa1f2 100644 --- a/cli/version.rs +++ b/cli/version.rs @@ -3,11 +3,30 @@ pub const GIT_COMMIT_HASH: &str = env!("GIT_COMMIT_HASH"); pub const TYPESCRIPT: &str = env!("TS_VERSION"); -pub fn deno() -> String { - let version = env!("CARGO_PKG_VERSION"); - option_env!("DENO_CANARY") - .map(|_| format!("{}+{}", version, &GIT_COMMIT_HASH[..7])) - .unwrap_or_else(|| version.to_string()) +pub fn deno() -> &'static str { + if is_canary() { + concat!( + env!("CARGO_PKG_VERSION"), + "+", + env!("GIT_COMMIT_HASH_SHORT") + ) + } else { + env!("CARGO_PKG_VERSION") + } +} + +// Keep this in sync with `deno()` above +pub fn get_user_agent() -> &'static str { + if is_canary() { + concat!( + "Deno/", + env!("CARGO_PKG_VERSION"), + "+", + env!("GIT_COMMIT_HASH_SHORT") + ) + } else { + concat!("Deno/", env!("CARGO_PKG_VERSION")) + } } pub fn is_canary() -> bool { @@ -21,7 +40,3 @@ pub fn release_version_or_canary_commit_hash() -> &'static str { env!("CARGO_PKG_VERSION") } } - -pub fn get_user_agent() -> String { - format!("Deno/{}", deno()) -} |