diff options
author | Aleksey Kladov <[email protected]> | 2018-07-30 16:11:33 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-07-30 16:11:33 +0100 |
commit | beaddb478097223c87e507bf9367d85d86df5d06 (patch) | |
tree | 7490bad360bc226403183d8900c16f170f712626 /src/yellow/green.rs | |
parent | 60e8a845cafb9630caa034b886368160a12dcd64 (diff) |
Intern static tokens
Diffstat (limited to 'src/yellow/green.rs')
-rw-r--r-- | src/yellow/green.rs | 19 |
1 files changed, 13 insertions, 6 deletions
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() { | |||
81 | #[derive(Clone, Debug)] | 81 | #[derive(Clone, Debug)] |
82 | pub(crate) enum GreenLeaf { | 82 | pub(crate) enum GreenLeaf { |
83 | Whitespace { newlines: u8, spaces: u8 }, | 83 | Whitespace { newlines: u8, spaces: u8 }, |
84 | Token { kind: SyntaxKind, text: Arc<str> }, | 84 | Token { kind: SyntaxKind, text: Option<Arc<str>> }, |
85 | } | 85 | } |
86 | 86 | ||
87 | impl GreenLeaf { | 87 | impl GreenLeaf { |
@@ -96,10 +96,14 @@ impl GreenLeaf { | |||
96 | }; | 96 | }; |
97 | } | 97 | } |
98 | } | 98 | } |
99 | GreenLeaf::Token { | 99 | let text = match SyntaxKind::static_text(kind) { |
100 | kind, | 100 | Some(t) => { |
101 | text: text.to_owned().into_boxed_str().into(), | 101 | debug_assert_eq!(t, text); |
102 | } | 102 | None |
103 | } | ||
104 | None => Some(text.to_owned().into_boxed_str().into()), | ||
105 | }; | ||
106 | GreenLeaf::Token { kind, text } | ||
103 | } | 107 | } |
104 | 108 | ||
105 | pub(crate) fn kind(&self) -> SyntaxKind { | 109 | pub(crate) fn kind(&self) -> SyntaxKind { |
@@ -117,7 +121,10 @@ impl GreenLeaf { | |||
117 | assert!(newlines <= N_NEWLINES && spaces <= N_SPACES); | 121 | assert!(newlines <= N_NEWLINES && spaces <= N_SPACES); |
118 | &WS[N_NEWLINES - newlines..N_NEWLINES + spaces] | 122 | &WS[N_NEWLINES - newlines..N_NEWLINES + spaces] |
119 | } | 123 | } |
120 | GreenLeaf::Token { text, .. } => text, | 124 | GreenLeaf::Token { kind, text, } => match text { |
125 | None => kind.static_text().unwrap(), | ||
126 | Some(t) => t, | ||
127 | }, | ||
121 | } | 128 | } |
122 | } | 129 | } |
123 | 130 | ||