Skip to content

Commit 17c8167

Browse files
author
bors-servo
committed
Auto merge of servo#81 - pcwalton:dedivision, r=SimonSapin
tokenizer: Remove division from the floating point conversion code. It's quite slow compared to multiplication. r? @SimonSapin <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/rust-cssparser/81) <!-- Reviewable:end -->
2 parents 53a543d + 001ca30 commit 17c8167

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)