From f0519c8001329df8e0ee798ddd593bac236e543a Mon Sep 17 00:00:00 2001 From: topecongiro Date: Mon, 19 Feb 2018 12:36:36 +0900 Subject: [PATCH] Avoid running lookup_line_range when file_lines are not specified --- rustfmt-config/src/file_lines.rs | 5 +++++ rustfmt-core/src/utils.rs | 9 +++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/rustfmt-config/src/file_lines.rs b/rustfmt-config/src/file_lines.rs index 87e201345de..714f33c03dc 100644 --- a/rustfmt-config/src/file_lines.rs +++ b/rustfmt-config/src/file_lines.rs @@ -132,6 +132,11 @@ pub fn all() -> FileLines { FileLines(None) } + /// Returns true if this `FileLines` contains all lines in all files. + pub fn is_all(&self) -> bool { + self.0.is_none() + } + pub fn from_ranges(mut ranges: HashMap>) -> FileLines { normalize_ranges(&mut ranges); FileLines(Some(ranges)) diff --git a/rustfmt-core/src/utils.rs b/rustfmt-core/src/utils.rs index d1bb7e26f5e..20b30089d70 100644 --- a/rustfmt-core/src/utils.rs +++ b/rustfmt-core/src/utils.rs @@ -278,10 +278,11 @@ pub fn mk_sp(lo: BytePos, hi: BytePos) -> Span { // Return true if the given span does not intersect with file lines. macro_rules! out_of_file_lines_range { ($self: ident, $span: expr) => { - !$self - .config - .file_lines() - .intersects(&$self.codemap.lookup_line_range($span)) + !$self.config.file_lines().is_all() + && !$self + .config + .file_lines() + .intersects(&$self.codemap.lookup_line_range($span)) }; } -- 2.44.0