Replace a redundant escape
variable with nested matches.
This has a non-trivial performance effect due to the branch prediction, but is expected to be no slower than the older code and, at least in some cases, is slightly faster for a string-heavy JSON.
This commit is contained in:
parent
206e19edb4
commit
9550063275
@ -307,15 +307,23 @@ impl<Iter> Deserializer<Iter>
|
||||
fn parse_string(&mut self) -> Result<(), Error> {
|
||||
self.str_buf.clear();
|
||||
|
||||
let mut escape = false;
|
||||
|
||||
loop {
|
||||
let ch = match try!(self.next_char()) {
|
||||
Some(ch) => ch,
|
||||
None => { return Err(self.error(ErrorCode::EOFWhileParsingString)); }
|
||||
};
|
||||
|
||||
if escape {
|
||||
match ch {
|
||||
b'"' => {
|
||||
try!(self.bump());
|
||||
return Ok(());
|
||||
}
|
||||
b'\\' => {
|
||||
let ch = match try!(self.next_char()) {
|
||||
Some(ch) => ch,
|
||||
None => { return Err(self.error(ErrorCode::EOFWhileParsingString)); }
|
||||
};
|
||||
|
||||
match ch {
|
||||
b'"' => self.str_buf.push(b'"'),
|
||||
b'\\' => self.str_buf.push(b'\\'),
|
||||
@ -377,15 +385,6 @@ impl<Iter> Deserializer<Iter>
|
||||
return Err(self.error(ErrorCode::InvalidEscape));
|
||||
}
|
||||
}
|
||||
escape = false;
|
||||
} else {
|
||||
match ch {
|
||||
b'"' => {
|
||||
try!(self.bump());
|
||||
return Ok(());
|
||||
}
|
||||
b'\\' => {
|
||||
escape = true;
|
||||
}
|
||||
ch => {
|
||||
self.str_buf.push(ch);
|
||||
@ -393,7 +392,6 @@ impl<Iter> Deserializer<Iter>
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_object_colon(&mut self) -> Result<(), Error> {
|
||||
try!(self.parse_whitespace());
|
||||
|
Loading…
x
Reference in New Issue
Block a user