Skip to content

Commit

Permalink
fine tuning
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurprs committed Sep 6, 2024
1 parent 2df61db commit 1b274f7
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ where
self.read.discard();
}

#[cold]
#[inline]
fn error(&self, reason: ErrorCode) -> Error {
let offset = self.read.offset();
Error::syntax(reason, offset)
Expand Down Expand Up @@ -449,13 +449,15 @@ where
Ok(self.read.take_buffer())
}

#[inline]
fn convert_str<'a>(buf: &'a [u8], offset: u64) -> Result<&'a str> {
match str::from_utf8(buf) {
Ok(s) => Ok(s),
Err(_) => Err(Error::syntax(ErrorCode::InvalidUtf8, offset)),
}
}

#[inline]
fn parse_str<V>(&mut self, len: Option<usize>, visitor: V) -> Result<V::Value>
where
V: de::Visitor<'de>,
Expand Down Expand Up @@ -524,6 +526,7 @@ where
self.recursion_checked(|de| de.parse_value::<_, Valid>(visitor))
}

#[inline]
fn recursion_checked<F, T>(&mut self, f: F) -> Result<T>
where
F: FnOnce(&mut Deserializer<R, O>) -> Result<T>,
Expand Down Expand Up @@ -629,6 +632,7 @@ where
})
}

#[inline]
fn parse_float(&mut self, magnitude: u8) -> Result<f64> {
let mut buf = [0; 8];
let bytes = 1 << (magnitude - 1);
Expand Down Expand Up @@ -752,7 +756,6 @@ where
// Major type 7: floating-point numbers and other simple data types that need no content
0xf4..=0xf5 if Valid::BOOL => visitor.visit_bool(byte == 0xf5),
0xf6..=0xf7 if Valid::NULL => visitor.visit_unit(),
// 0xf8 => Err(self.error(ErrorCode::UnassignedCode)),
0xf9..=0xfb if Valid::FLOAT => {
let value = self.parse_float(byte - 0xf9 + 2)?;
visitor.visit_f64(value)
Expand Down

0 comments on commit 1b274f7

Please sign in to comment.