@@ -16,15 +16,6 @@ rewind_to_string_start(struct tok_state *tok, const char *start,
1616 tok -> lineno = location .lineno ;
1717}
1818
19- static tokenizer_comments *
20- current_comments (const struct tok_state * tok )
21- {
22- tokenizer_comments * comments = tok -> ftstring_comments ;
23- return comments != NULL &&
24- comments -> mode_index == _PyLexer_ModeDepth (tok )
25- ? comments : NULL ;
26- }
27-
2819int
2920_PyLexer_record_ftstring_comment (struct tok_state * tok , const char * start ,
3021 const char * end )
@@ -34,9 +25,8 @@ _PyLexer_record_ftstring_comment(struct tok_state *tok, const char *start,
3425 return 0 ;
3526 }
3627 assert (mode -> expr_span .start >= 0 );
37- tokenizer_comments * comments = current_comments ( tok ) ;
28+ tokenizer_comments * comments = mode -> comments ;
3829 if (comments == NULL || comments -> count == comments -> capacity ) {
39- int create = comments == NULL ;
4030 Py_ssize_t max_capacity = (PY_SSIZE_T_MAX -
4131 (Py_ssize_t )sizeof (* comments )) /
4232 (Py_ssize_t )sizeof (* comments -> spans );
@@ -53,13 +43,11 @@ _PyLexer_record_ftstring_comment(struct tok_state *tok, const char *start,
5343 return -1 ;
5444 }
5545 comments = resized ;
56- if (create ) {
57- comments -> previous = tok -> ftstring_comments ;
46+ if (mode -> comments == NULL ) {
5847 comments -> count = 0 ;
59- comments -> mode_index = _PyLexer_ModeDepth (tok );
6048 }
6149 comments -> capacity = capacity ;
62- tok -> ftstring_comments = comments ;
50+ mode -> comments = comments ;
6351 }
6452 comments -> spans [comments -> count ++ ] =
6553 _PyLexer_BufferSpan (tok , start , end );
@@ -79,7 +67,7 @@ _PyLexer_set_ftstring_expr_metadata(struct tok_state *tok, struct token *token)
7967 Py_ssize_t expr_len ;
8068 const char * expr = _PyLexer_BufferSpanView (
8169 tok , tok_mode -> expr_span , & expr_len );
82- tokenizer_comments * comments = current_comments ( tok ) ;
70+ tokenizer_comments * comments = tok_mode -> comments ;
8371 PyObject * res ;
8472 if (comments != NULL && comments -> count > 0 ) {
8573 Py_ssize_t stripped_size = expr_len ;
@@ -130,9 +118,10 @@ _PyLexer_set_ftstring_expr_metadata(struct tok_state *tok, struct token *token)
130118void
131119_PyLexer_begin_ftstring_expr (struct tok_state * tok )
132120{
133- _PyLexer_CurrentMode (tok )-> expr_span = (_PyTok_Span ){
121+ tokenizer_mode * mode = _PyLexer_CurrentMode (tok );
122+ mode -> expr_span = (_PyTok_Span ){
134123 _PyLexer_BufferOffset (tok , tok -> cur ), -1 };
135- tokenizer_comments * comments = current_comments ( tok ) ;
124+ tokenizer_comments * comments = mode -> comments ;
136125 if (comments != NULL ) {
137126 comments -> count = 0 ;
138127 }
@@ -411,11 +400,6 @@ _PyLexer_get_fstring_mode(struct tok_state *tok, tokenizer_mode* current_tok, st
411400
412401 p_start = tok -> start ;
413402 p_end = tok -> cur ;
414- tokenizer_comments * comments = current_comments (tok );
415- if (comments != NULL ) {
416- tok -> ftstring_comments = comments -> previous ;
417- PyMem_Free (comments );
418- }
419403 _PyLexer_PopMode (tok );
420404 return MAKE_TOKEN (FTSTRING_END (current_tok ));
421405
0 commit comments