2 ms·
Interesting, you appear to be hitting some kind of pathological case with the `vec!` macro. Apparently it doesn't like being used with a 15,000-line literal. :P
by kibwen 5y ago
Interesting, you appear to be hitting some kind of pathological case with the `vec!` macro. Apparently it doesn't like being used with a 15,000-line literal. :P Fortunately you're right, there's a different way to do this, which AFAICT doesn't suffer from the same pathology. I replaced this:
pub struct Choice {
pub word: String,
pub avg_remaining: f64,
}
pub fn root_choices() -> Vec<Choice> {
vec![
Choice { word: "roate".to_string(), avg_remaining: 60.42462203023758 },
with this:
use std::borrow::Cow;
#[derive(Clone)]
pub struct Choice<'a> {
pub word: Cow<'a, str>,
pub avg_remaining: f64,
}
pub const ROOT_CHOICES: &[Choice] = &[
Choice { word: Cow::Borrowed("roate"), avg_remaining: 60.42462203023758 },
and it brought the time of `cargo clean && cargo build --release` down from 345 seconds to 13 seconds. I consider this a compiler bug, I'll file it if I can't find an existing issue.
- espadrine 5y agoOh, thanks! That is exactly what I wanted; a global constant makes more sense for this use-case.