Repository: astral-sh/ruff
File: crates/ruff_linter/src/suppression.rs (Rust)

Code before:
            .iter()
            .copied()
            .filter_map(|comment_range| {
                let mut parser = SuppressionParser::new(self.source, comment_range);
                match parser.parse_comment() {
                    Ok(comment) => Some(comment),
                    Err(ParseError {
                        kind: ParseErrorKind::NotASuppression,
                        ..
                    }) => None,
                    Err(error) => {
                        errors.push(error);
                        None
                    }
                }
            })
            .peekable();

        'comments: while let Some(suppression) = suppressions.peek() {
            let last_indent = tokens
                .before(suppression.range.start())
                .iter()
                .rfind(|token| token.kind() == TokenKind::Indent)
                .map(|token| self.source.slice(token))
                .unwrap_or_default();

            indents.push(last_indent);

            let tokens = tokens.after(suppression.range.start());

            // Iterate through tokens, tracking indentation, filtering trailing comments, and then
            // looking for matching comments from the previous block when reaching a dedent token.
            for (token_index, token) in tokens.iter().enumerate() {
                let current_indent = indents.last().copied().unwrap_or_default();
                match token.kind() {
                    TokenKind::Indent => {
                        indents.push(self.source.slice(token));
                    }
                    TokenKind::Dedent => {
                        self.match_comments(current_indent, token.range());

                        indents.pop();

                        if indents.is_empty() {
                            // OR if self.pending is empty?
                            continue 'comments;
                        }
                    }
                    TokenKind::Comment => {
                        let Some(suppression) =
                            suppressions.next_if(|suppression| suppression.range == token.range())

Review comment (suggestion):
I think we should clear indents after each iteration. We use it more as a scratch pad and we only use the same instance to avoid allocating multiple vecs`

```suggestion
        'comments: while let Some(suppression) = suppressions.peek() {
        		indents.clear();
```

Code after:

    pub(crate) fn load_from_tokens(mut self, tokens: &Tokens, indexer: &Indexer) -> Suppressions {
        let mut indents: Vec<&str> = vec![];
        let mut errors = Vec::new();

        let mut suppressions = indexer
            .comment_ranges()
            .iter()
            .copied()
            .filter_map(|comment_range| {
                let mut parser = SuppressionParser::new(self.source, comment_range);
                match parser.parse_comment() {
                    Ok(comment) => Some(comment),
                    Err(ParseError {
                        kind: ParseErrorKind::NotASuppression,
                        ..
                    }) => None,
                    Err(error) => {
                        errors.push(error);
                        None
                    }
                }
            })
            .peekable();

        'comments: while let Some(suppression) = suppressions.peek() {
            indents.clear();

            let (before, after) = tokens.split_at(suppression.range.start());
            let last_indent = before
                .iter()
                .rfind(|token| token.kind() == TokenKind::Indent)
                .map(|token| self.source.slice(token))
                .unwrap_or_default();

            indents.push(last_indent);

            // Iterate through tokens, tracking indentation, filtering trailing comments, and then
            // looking for matching comments from the previous block when reaching a dedent token.
            for (token_index, token) in after.iter().enumerate() {
                let current_indent = indents.last().copied().unwrap_or_default();
                match token.kind() {
                    TokenKind::Indent => {
                        indents.push(self.source.slice(token));
                    }
                    TokenKind::Dedent => {
                        self.match_comments(current_indent, token.range());

                        indents.pop();

                        if indents.is_empty() || self.pending.is_empty() {