Skip to content

Commit 001ca30

Browse files
committed
tokenizer: Remove division from the floating point conversion code.
It's quite slow compared to multiplication.
1 parent 53a543d commit 001ca30

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/tokenizer.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -686,10 +686,10 @@ fn consume_numeric<'a>(tokenizer: &mut Tokenizer<'a>) -> Token<'a> {
686686
&& matches!(tokenizer.char_at(1), '0'...'9') {
687687
is_integer = false;
688688
tokenizer.advance(1); // Consume '.'
689-
let mut divisor = 10.;
689+
let mut factor = 0.1;
690690
while let Some(digit) = tokenizer.next_char().to_digit(10) {
691-
fractional_part += digit as f64 / divisor;
692-
divisor *= 10.;
691+
fractional_part += digit as f64 * factor;
692+
factor *= 0.1;
693693
tokenizer.advance(1);
694694
if tokenizer.is_eof() {
695695
break

0 commit comments

Comments
 (0)