mirror of
				https://github.com/astral-sh/ruff.git
				synced 2025-11-03 21:24:29 +00:00 
			
		
		
		
	Use a sorted vector for block comments (#9337)
## Summary I realized that we can avoid allocating a hash map here.
This commit is contained in:
		
							parent
							
								
									686abbc97a
								
							
						
					
					
						commit
						cea2ec8dd0
					
				
					 2 changed files with 4 additions and 6 deletions
				
			
		| 
						 | 
					@ -2,10 +2,8 @@ use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation};
 | 
				
			||||||
use ruff_macros::{derive_message_formats, violation};
 | 
					use ruff_macros::{derive_message_formats, violation};
 | 
				
			||||||
use ruff_python_index::Indexer;
 | 
					use ruff_python_index::Indexer;
 | 
				
			||||||
use ruff_python_trivia::is_python_whitespace;
 | 
					use ruff_python_trivia::is_python_whitespace;
 | 
				
			||||||
 | 
					 | 
				
			||||||
use ruff_source_file::Locator;
 | 
					use ruff_source_file::Locator;
 | 
				
			||||||
use ruff_text_size::{TextRange, TextSize};
 | 
					use ruff_text_size::{TextRange, TextSize};
 | 
				
			||||||
use rustc_hash::FxHashSet;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// ## What it does
 | 
					/// ## What it does
 | 
				
			||||||
/// Checks for a # symbol appearing on a line not followed by an actual comment.
 | 
					/// Checks for a # symbol appearing on a line not followed by an actual comment.
 | 
				
			||||||
| 
						 | 
					@ -50,11 +48,11 @@ pub(crate) fn empty_comments(
 | 
				
			||||||
    indexer: &Indexer,
 | 
					    indexer: &Indexer,
 | 
				
			||||||
    locator: &Locator,
 | 
					    locator: &Locator,
 | 
				
			||||||
) {
 | 
					) {
 | 
				
			||||||
    let block_comments = FxHashSet::from_iter(indexer.comment_ranges().block_comments(locator));
 | 
					    let block_comments = indexer.comment_ranges().block_comments(locator);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for range in indexer.comment_ranges() {
 | 
					    for range in indexer.comment_ranges() {
 | 
				
			||||||
        // Ignore comments that are part of multi-line "comment blocks".
 | 
					        // Ignore comments that are part of multi-line "comment blocks".
 | 
				
			||||||
        if block_comments.contains(&range.start()) {
 | 
					        if block_comments.binary_search(&range.start()).is_ok() {
 | 
				
			||||||
            continue;
 | 
					            continue;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -54,8 +54,8 @@ impl CommentRanges {
 | 
				
			||||||
    /// own-line comments in which the comment hash (`#`) appears in the same
 | 
					    /// own-line comments in which the comment hash (`#`) appears in the same
 | 
				
			||||||
    /// column in each line, and at least one comment is non-empty.
 | 
					    /// column in each line, and at least one comment is non-empty.
 | 
				
			||||||
    ///
 | 
					    ///
 | 
				
			||||||
    /// Returns a vector containing the offset of the leading hash (`#`) for
 | 
					    /// Returns a sorted vector containing the offset of the leading hash (`#`)
 | 
				
			||||||
    /// each comment in any block comment.
 | 
					    /// for each comment in any block comment.
 | 
				
			||||||
    ///
 | 
					    ///
 | 
				
			||||||
    /// ## Examples
 | 
					    /// ## Examples
 | 
				
			||||||
    /// ```python
 | 
					    /// ```python
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue