Approximate tokens len (#9546)

This commit is contained in:
Micha Reiser 2024-01-19 17:39:37 +01:00 committed by GitHub
parent b3a6f0ce81
commit 47ad7b4500
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 38 additions and 13 deletions

View file

@ -2,7 +2,7 @@ use std::fmt::Debug;
use ruff_python_ast::PySourceType;
use ruff_python_parser::lexer::{lex, LexResult, LexicalError};
use ruff_python_parser::{AsMode, Tok};
use ruff_python_parser::{allocate_tokens_vec, AsMode, Tok};
use ruff_python_trivia::CommentRanges;
use ruff_text_size::TextRange;
@ -28,7 +28,7 @@ pub fn tokens_and_ranges(
source: &str,
source_type: PySourceType,
) -> Result<(Vec<LexResult>, CommentRanges), LexicalError> {
let mut tokens = Vec::new();
let mut tokens = allocate_tokens_vec(source);
let mut comment_ranges = CommentRangesBuilder::default();
for result in lex(source, source_type.as_mode()) {