Skip to content

Commit aa530bf

Browse files
Read from &[u8] instead of using stringreader (#20)
This avoids reliance on an unnecessary and deprecated dependency. The performance should also be better because it avoids dynamic dispatch.
1 parent a05f1d3 commit aa530bf

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

lib/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ strum = { version = "0.26.3", features = ["derive"] }
2323
as-any = "0.3.0"
2424
rand = "0.8.5"
2525
web-time = "1.1.0"
26-
stringreader = "0.1.1"
2726

2827
[features]
2928
stream-json-parser = []

lib/src/json/json_tokenizer.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
//! Tokenizer for the streamed JSON parser.
22
use std::io::{self, Read};
33

4-
use stringreader::StringReader;
5-
64
#[derive(Debug)]
75
pub(super) enum Number {
86
Int(i32),
@@ -59,15 +57,15 @@ impl JsonValue {
5957
}
6058

6159
pub(super) struct JsonTokenizer<'a> {
62-
reader: Box<dyn Read + 'a>,
60+
json: &'a [u8],
6361
lookahead: Option<char>,
6462
skip_whitespaces: bool,
6563
}
6664

6765
impl<'a> JsonTokenizer<'a> {
6866
pub(super) fn new_from_str(s: &'a str) -> JsonTokenizer<'a> {
6967
JsonTokenizer {
70-
reader: Box::new(StringReader::new(s)) as Box<dyn Read + 'a>,
68+
json: s.as_bytes(),
7169
lookahead: None,
7270
skip_whitespaces: true,
7371
}
@@ -103,7 +101,7 @@ impl<'a> JsonTokenizer<'a> {
103101

104102
// Read bytes until a valid UTF-8 character is formed
105103
loop {
106-
self.reader.read_exact(&mut temp_buf)?;
104+
self.json.read_exact(&mut temp_buf)?;
107105
utf8_char.push(temp_buf[0]);
108106

109107
if let Ok(utf8_str) = std::str::from_utf8(&utf8_char) {

0 commit comments

Comments
 (0)