Skip to content

Commit

Permalink
refactor min/max
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Dec 17, 2024
1 parent d571140 commit 542c552
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions crates/oxc_codegen/src/sourcemap_builder.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
use std::{path::Path, sync::Arc};
use std::{
cmp::{max, min},
path::Path,
sync::Arc,
};

use nonmax::NonMaxU32;
use oxc_index::{Idx, IndexVec};
Expand Down Expand Up @@ -168,8 +172,8 @@ impl SourcemapBuilder {
let lines = &self.line_offset_tables.lines;
let mut idx = self.last_line_lookup;

let cap = (idx + 16).min(lines.len() - 1);
idx = (idx + 1).min(cap);
let cap = min(idx + 16, lines.len() - 1);
idx = min(idx + 1, cap);
while idx < cap && lines[idx].byte_offset_to_start_of_line <= position {
idx += 1;
}
Expand All @@ -188,7 +192,7 @@ impl SourcemapBuilder {
let mut idx = self.last_line_lookup;

let cap = idx.saturating_sub(16);
idx = idx.saturating_sub(1).max(cap);
idx = max(idx.saturating_sub(1), cap);
while idx > cap && lines[idx].byte_offset_to_start_of_line > position {
idx -= 1;
}
Expand Down

0 comments on commit 542c552

Please sign in to comment.