Skip to content

Commit f0d25e5

Browse files
committed
no need to use Rc in lexer
1 parent e5ae536 commit f0d25e5

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,5 @@ bench = true
4646
debug = true
4747

4848
[[bench]]
49-
name = "formatting"
49+
name = "parsing"
5050
harness = false

benches/parsing.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ use std::fs;
44
use cirru_parser::parse;
55

66
fn criterion_benchmark(c: &mut Criterion) {
7-
let large_demo = "/Users/chenyong/repo/calcit-lang/editor/compact.cirru";
7+
let large_demo = "/Users/chenyong/repo/calcit-lang/editor/calcit.cirru";
88
let content = fs::read_to_string(large_demo).unwrap();
99

1010
c.bench_function("parse", |b| {
1111
b.iter(|| {
12-
let _ = parse(&content);
12+
let _ = parse(&content).expect("parsed");
1313
})
1414
});
1515
}

src/parser.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,28 +149,28 @@ pub fn lex(initial_code: &str) -> Result<CirruLexItemList, String> {
149149
},
150150
CirruLexState::Token => match c {
151151
' ' => {
152-
acc.push(CirruLexItem::Str(buffer.into()));
152+
acc.push(CirruLexItem::Str(buffer));
153153
state = CirruLexState::Space;
154154
buffer = String::from("");
155155
}
156156
'"' => {
157-
acc.push(CirruLexItem::Str(buffer.into()));
157+
acc.push(CirruLexItem::Str(buffer));
158158
state = CirruLexState::Str;
159159
buffer = String::from("");
160160
}
161161
'\n' => {
162-
acc.push(CirruLexItem::Str(buffer.into()));
162+
acc.push(CirruLexItem::Str(buffer));
163163
state = CirruLexState::Indent;
164164
buffer = String::from("");
165165
}
166166
'(' => {
167-
acc.push(CirruLexItem::Str(buffer.into()));
167+
acc.push(CirruLexItem::Str(buffer));
168168
acc.push(CirruLexItem::Open);
169169
state = CirruLexState::Space;
170170
buffer = String::from("")
171171
}
172172
')' => {
173-
acc.push(CirruLexItem::Str(buffer.into()));
173+
acc.push(CirruLexItem::Str(buffer));
174174
acc.push(CirruLexItem::Close);
175175
state = CirruLexState::Space;
176176
buffer = String::from("")
@@ -182,7 +182,7 @@ pub fn lex(initial_code: &str) -> Result<CirruLexItemList, String> {
182182
},
183183
CirruLexState::Str => match c {
184184
'"' => {
185-
acc.push(CirruLexItem::Str(buffer.into()));
185+
acc.push(CirruLexItem::Str(buffer));
186186
state = CirruLexState::Space;
187187
buffer = String::from("");
188188
}
@@ -268,7 +268,7 @@ pub fn lex(initial_code: &str) -> Result<CirruLexItemList, String> {
268268
match state {
269269
CirruLexState::Space => Ok(acc),
270270
CirruLexState::Token => {
271-
acc.push(CirruLexItem::Str(buffer.into()));
271+
acc.push(CirruLexItem::Str(buffer));
272272
Ok(acc)
273273
}
274274
CirruLexState::Escape => Err(String::from("unknown escape")),

src/primes.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use bincode::{Decode, Encode};
2+
use std::clone::Clone;
23
use std::fmt;
34
use std::hash::Hash;
45
use std::str;
56
use std::sync::Arc;
6-
use std::{clone::Clone, rc::Rc};
77

88
#[cfg(feature = "use-serde")]
99
use serde::{
@@ -174,7 +174,7 @@ pub enum CirruLexItem {
174174
Close,
175175
// supposed to be enough with indentation of 255
176176
Indent(u8),
177-
Str(Rc<str>),
177+
Str(String),
178178
}
179179

180180
impl From<&str> for CirruLexItem {

0 commit comments

Comments
 (0)