From 542c5524caf7c9dad87fab5b790eea0ef12cd836 Mon Sep 17 00:00:00 2001 From: overlookmotel Date: Tue, 17 Dec 2024 10:28:59 +0000 Subject: [PATCH] refactor min/max --- crates/oxc_codegen/src/sourcemap_builder.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/crates/oxc_codegen/src/sourcemap_builder.rs b/crates/oxc_codegen/src/sourcemap_builder.rs index fa55bb84cc4654..2c558734de5bdf 100644 --- a/crates/oxc_codegen/src/sourcemap_builder.rs +++ b/crates/oxc_codegen/src/sourcemap_builder.rs @@ -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}; @@ -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; } @@ -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; }