From beaddb478097223c87e507bf9367d85d86df5d06 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 30 Jul 2018 18:11:33 +0300 Subject: Intern static tokens --- src/yellow/green.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'src/yellow') diff --git a/src/yellow/green.rs b/src/yellow/green.rs index 507e4d57e..cda4e2167 100644 --- a/src/yellow/green.rs +++ b/src/yellow/green.rs @@ -81,7 +81,7 @@ fn assert_send_sync() { #[derive(Clone, Debug)] pub(crate) enum GreenLeaf { Whitespace { newlines: u8, spaces: u8 }, - Token { kind: SyntaxKind, text: Arc }, + Token { kind: SyntaxKind, text: Option> }, } impl GreenLeaf { @@ -96,10 +96,14 @@ impl GreenLeaf { }; } } - GreenLeaf::Token { - kind, - text: text.to_owned().into_boxed_str().into(), - } + let text = match SyntaxKind::static_text(kind) { + Some(t) => { + debug_assert_eq!(t, text); + None + } + None => Some(text.to_owned().into_boxed_str().into()), + }; + GreenLeaf::Token { kind, text } } pub(crate) fn kind(&self) -> SyntaxKind { @@ -117,7 +121,10 @@ impl GreenLeaf { assert!(newlines <= N_NEWLINES && spaces <= N_SPACES); &WS[N_NEWLINES - newlines..N_NEWLINES + spaces] } - GreenLeaf::Token { text, .. } => text, + GreenLeaf::Token { kind, text, } => match text { + None => kind.static_text().unwrap(), + Some(t) => t, + }, } } -- cgit v1.2.3