diff --git a/orgize/Cargo.toml b/orgize/Cargo.toml index f7bde26..45145c7 100644 --- a/orgize/Cargo.toml +++ b/orgize/Cargo.toml @@ -24,6 +24,7 @@ bytecount = "0.6.0" chrono = { version = "0.4.9", optional = true } indextree = "4.0.0" jetscii = "0.4.4" +lazy_static = "1.4.0" memchr = "2.2.1" nom = "5.0.1" serde = { version = "1.0.100", optional = true, features = ["derive"] } @@ -31,7 +32,6 @@ serde_indextree = { version = "0.2.0", optional = true } syntect = { version = "3.2.1", optional = true } [dev-dependencies] -lazy_static = "1.4.0" pretty_assertions = "0.6.1" serde_json = "1.0.40" slugify = "0.1.0" diff --git a/orgize/src/export/html.rs b/orgize/src/export/html.rs index c15c0cc..5204702 100644 --- a/orgize/src/export/html.rs +++ b/orgize/src/export/html.rs @@ -1,6 +1,6 @@ use super::write_datetime; use crate::elements::Element; -use jetscii::bytes; +use jetscii::{bytes, BytesConst}; use std::fmt; use std::io::{Error, Write}; use std::marker::PhantomData; @@ -11,7 +11,12 @@ impl> fmt::Display for Escape { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut pos = 0; let bytes = self.0.as_ref().as_bytes(); - while let Some(off) = bytes!(b'<', b'>', b'&', b'\'', b'"').find(&bytes[pos..]) { + + lazy_static::lazy_static! { + static ref ESCAPE_BYTES: BytesConst = bytes!(b'<', b'>', b'&', b'\'', b'"'); + } + + while let Some(off) = ESCAPE_BYTES.find(&bytes[pos..]) { write!(f, "{}", &self.0.as_ref()[pos..pos + off])?; pos += off + 1; diff --git a/orgize/src/parsers.rs b/orgize/src/parsers.rs index 4afdbd4..0791b1d 100644 --- a/orgize/src/parsers.rs +++ b/orgize/src/parsers.rs @@ -5,7 +5,7 @@ use std::iter::once; use std::marker::PhantomData; use indextree::{Arena, NodeId}; -use jetscii::bytes; +use jetscii::{bytes, BytesConst}; use memchr::{memchr, memchr_iter}; use nom::{ bytes::complete::take_while1, combinator::verify, error::ErrorKind, error_position, Err, @@ -457,8 +457,6 @@ pub fn parse_inlines<'a, T: ElementArena<'a>>( let mut text = tail; let mut pos = 0; - let bs = bytes!(b'@', b'<', b'[', b' ', b'(', b'{', b'\'', b'"', b'\n'); - macro_rules! insert_text { ($value:expr) => { arena.insert_before_last_child( @@ -479,7 +477,12 @@ pub fn parse_inlines<'a, T: ElementArena<'a>>( }; } - while let Some(off) = bs.find(tail.as_bytes()) { + lazy_static::lazy_static! { + static ref PRE_BYTES: BytesConst = + bytes!(b'@', b'<', b'[', b' ', b'(', b'{', b'\'', b'"', b'\n'); + } + + while let Some(off) = PRE_BYTES.find(tail.as_bytes()) { match tail.as_bytes()[off] { b'{' => { if let Some(new_tail) = parse_inline(&tail[off..], arena, containers, parent) {