Skip to content

Commit a882cd4

Browse files
authored
Merge pull request #387 from serde-rs/fix-position
Stop instantiating fix_position so many times
2 parents da04452 + c8f0eb8 commit a882cd4

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/de.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,13 @@ impl<'de, R: Read<'de>> Deserializer<R> {
147147
}
148148

149149
/// Error caused by a byte from next_char().
150-
fn error(&mut self, reason: ErrorCode) -> Error {
150+
fn error(&self, reason: ErrorCode) -> Error {
151151
let pos = self.read.position();
152152
Error::syntax(reason, pos.line, pos.column)
153153
}
154154

155155
/// Error caused by a byte from peek().
156-
fn peek_error(&mut self, reason: ErrorCode) -> Error {
156+
fn peek_error(&self, reason: ErrorCode) -> Error {
157157
let pos = self.read.peek_position();
158158
Error::syntax(reason, pos.line, pos.column)
159159
}
@@ -256,10 +256,15 @@ impl<'de, R: Read<'de>> Deserializer<R> {
256256
// tell whether this should call `error` or `peek_error` so pick the
257257
// one that seems correct more often. Worst case, the position is
258258
// off by one character.
259-
Err(err) => Err(err.fix_position(|code| self.error(code))),
259+
Err(err) => Err(self.fix_position(err)),
260260
}
261261
}
262262

263+
#[cold]
264+
fn fix_position(&self, err: Error) -> Error {
265+
err.fix_position(move |code| self.error(code))
266+
}
267+
263268
fn parse_ident(&mut self, ident: &[u8]) -> Result<()> {
264269
for c in ident {
265270
if Some(*c) != try!(self.next_char()) {

0 commit comments

Comments
 (0)