Reuse locator in formatter comments (#7227)
**Summary** The comment visitor used to rebuild the locator for every comment. Instead, we now keep the locator on the builder. Follow-up to #6813. **Test Plan** No formatting changes.
This commit is contained in:
@@ -104,6 +104,7 @@ use ruff_python_ast::node::AnyNodeRef;
|
||||
use ruff_python_ast::visitor::preorder::{PreorderVisitor, TraversalSignal};
|
||||
use ruff_python_index::CommentRanges;
|
||||
use ruff_python_trivia::PythonWhitespace;
|
||||
use ruff_source_file::Locator;
|
||||
|
||||
use crate::comments::debug::{DebugComment, DebugComments};
|
||||
use crate::comments::map::{LeadingDanglingTrailing, MultiMap};
|
||||
@@ -325,7 +326,7 @@ impl<'a> Comments<'a> {
|
||||
let map = if comment_ranges.is_empty() {
|
||||
CommentsMap::new()
|
||||
} else {
|
||||
let mut builder = CommentsMapBuilder::default();
|
||||
let mut builder = CommentsMapBuilder::new(Locator::new(source_code.as_str()));
|
||||
CommentsVisitor::new(source_code, comment_ranges, &mut builder).visit(root);
|
||||
builder.finish()
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user