Skip to content

Commit

Permalink
use once_cell in config crate
Browse files Browse the repository at this point in the history
  • Loading branch information
mwcz committed Jan 28, 2022
1 parent 6c2ae11 commit e986239
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 17 deletions.
3 changes: 1 addition & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ name = "zola"
[dependencies]
atty = "0.2.11"
clap = { version = "3", features = ["derive"] }
lazy_static = "1.1"
termcolor = "1.0.4"
# Below is for the serve cmd
hyper = { version = "0.14.1", default-features = false, features = ["runtime", "server", "http2", "http1"] }
Expand Down
3 changes: 1 addition & 2 deletions components/config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ include = ["src/**/*"]

[dependencies]
serde = {version = "1.0", features = ["derive"] }
# TODO: remove me if we can get highlight to work with once_cell
lazy_static = "1"
once_cell = "1.9"

This comment has been minimized.

Copy link
@Keats

Keats Jan 28, 2022

Collaborator

you don't need to add once_cell here, just use use libs::once_cell::sync::Lazy in the highlighting file


errors = { path = "../errors" }
utils = { path = "../utils" }
Expand Down
17 changes: 6 additions & 11 deletions components/config/src/highlighting.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
use lazy_static::lazy_static;
use libs::syntect::dumps::from_binary;
use libs::syntect::highlighting::{Theme, ThemeSet};
use libs::syntect::html::ClassStyle;
use libs::syntect::parsing::{SyntaxReference, SyntaxSet};
use once_cell::sync::Lazy;

use crate::config::Config;

pub const CLASS_STYLE: ClassStyle = ClassStyle::SpacedPrefixed { prefix: "z-" };

// TODO: replace with once_cell. I was getting malloc error with sync::Lazy
lazy_static! {
pub static ref SYNTAX_SET: SyntaxSet = {
let ss: SyntaxSet =
from_binary(include_bytes!("../../../sublime/syntaxes/newlines.packdump"));
ss
};
pub static ref THEME_SET: ThemeSet =
from_binary(include_bytes!("../../../sublime/themes/all.themedump"));
}
pub static SYNTAX_SET: Lazy<SyntaxSet> =
Lazy::new(|| from_binary(include_bytes!("../../../sublime/syntaxes/newlines.packdump")));

pub static THEME_SET: Lazy<ThemeSet> =
Lazy::new(|| from_binary(include_bytes!("../../../sublime/themes/all.themedump")));

#[derive(Clone, Debug, PartialEq, Eq)]
pub enum HighlightSource {
Expand Down
1 change: 0 additions & 1 deletion components/site/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use std::fs::remove_dir_all;
use std::path::{Path, PathBuf};
use std::sync::{Arc, Mutex, RwLock};

// use lazy_static::lazy_static;
use libs::once_cell::sync::Lazy;
use libs::rayon::prelude::*;
use libs::tera::{Context, Tera};
Expand Down

2 comments on commit e986239

@Keats
Copy link
Collaborator

@Keats Keats commented on e986239 Jan 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the exact code I had that was causing malloc failures :( I just tried again and it works this time... the only thing that changed was a reboot since yesterday. Can you do a PR after removing the line from Cargo.toml?

@Keats
Copy link
Collaborator

@Keats Keats commented on e986239 Jan 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually nevermind, I had to apply the changes locally so I can just push it

Please sign in to comment.