summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Knaack <davidkna@users.noreply.github.com>2021-01-20 18:59:21 +0100
committerGitHub <noreply@github.com>2021-01-20 18:59:21 +0100
commitbb160d92079fb8f2f9f301159a54db0741aec41d (patch)
tree52deb8f53e52cb3ab6085c993ed3e4d63541b2dd
parent2532251a13a5605b020a1c076a372e300fc5723a (diff)
perf(elixir): evaluate version lazily (#2172)
-rw-r--r--docs/config/README.md12
-rw-r--r--src/configs/elixir.rs2
-rw-r--r--src/modules/elixir.rs20
3 files changed, 22 insertions, 12 deletions
diff --git a/docs/config/README.md b/docs/config/README.md
index fdc89a693..97c3095ae 100644
--- a/docs/config/README.md
+++ b/docs/config/README.md
@@ -808,12 +808,12 @@ The module will be shown if any of the following conditions are met:
### Options
-| Option | Default | Description |
-| ---------- | ------------------------------------------------------- | --------------------------------------------------------------- |
-| `symbol` | `"💧 "` | The symbol used before displaying the version of Elixir/Erlang. |
-| `style` | `"bold purple"` | The style for the module. |
-| `format` | `'via [$symbol$version \(OTP $otp_version\)]($style) '` | The format for the module elixir. |
-| `disabled` | `false` | Disables the `elixir` module. |
+| Option | Default | Description |
+| ---------- | --------------------------------------------------------- | --------------------------------------------------------------- |
+| `symbol` | `"💧 "` | The symbol used before displaying the version of Elixir/Erlang. |
+| `style` | `"bold purple"` | The style for the module. |
+| `format` | `'via [$symbol($version \(OTP $otp_version\) )]($style)'` | The format for the module elixir. |
+| `disabled` | `false` | Disables the `elixir` module. |
### Variables
diff --git a/src/configs/elixir.rs b/src/configs/elixir.rs
index 21a99cc90..ebe2a2711 100644
--- a/src/configs/elixir.rs
+++ b/src/configs/elixir.rs
@@ -13,7 +13,7 @@ pub struct ElixirConfig<'a> {
impl<'a> RootModuleConfig<'a> for ElixirConfig<'a> {
fn new() -> Self {
ElixirConfig {
- format: "via [$symbol$version \\(OTP $otp_version\\)]($style) ",
+ format: "via [$symbol($version \\(OTP $otp_version\\) )]($style)",
symbol: "💧 ",
style: "bold purple",
disabled: false,
diff --git a/src/modules/elixir.rs b/src/modules/elixir.rs
index 921e97afb..3fd31fa2d 100644
--- a/src/modules/elixir.rs
+++ b/src/modules/elixir.rs
@@ -4,7 +4,9 @@ use crate::configs::elixir::ElixirConfig;
use crate::formatter::StringFormatter;
use crate::utils;
+use once_cell::sync::Lazy;
use regex::Regex;
+use std::ops::Deref;
const ELIXIR_VERSION_PATTERN: &str = "\
Erlang/OTP (?P<otp>\\d+)[^\\n]+
@@ -21,7 +23,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
return None;
}
- let (otp_version, elixir_version) = get_elixir_version()?;
+ let versions = Lazy::new(get_elixir_version);
let mut module = context.new_module("elixir");
let config = ElixirConfig::try_load(module.config);
@@ -36,8 +38,16 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
_ => None,
})
.map(|variable| match variable {
- "version" => Some(Ok(&elixir_version)),
- "otp_version" => Some(Ok(&otp_version)),
+ "version" => versions
+ .deref()
+ .as_ref()
+ .map(|(_, elixir_version)| elixir_version)
+ .map(Ok),
+ "otp_version" => versions
+ .deref()
+ .as_ref()
+ .map(|(otp_version, _)| otp_version)
+ .map(Ok),
_ => None,
})
.parse(None)
@@ -110,8 +120,8 @@ Elixir 1.10 (compiled with Erlang/OTP 22)
File::create(dir.path().join("mix.exs"))?.sync_all()?;
let expected = Some(format!(
- "via {} ",
- Color::Purple.bold().paint("💧 1.10 (OTP 22)")
+ "via {}",
+ Color::Purple.bold().paint("💧 1.10 (OTP 22) ")
));
let output = ModuleRenderer::new("elixir").path(dir.path()).collect();