@@ -3116,7 +3116,7 @@ static rbs_ast_comment_t *parse_comment_lines(rbs_parser_t *parser, rbs_comment_
31163116 rbs_buffer_init (ALLOCATOR (), & rbs_buffer );
31173117
31183118 for (size_t i = 0 ; i < com -> line_tokens_count ; i ++ ) {
3119- rbs_token_t tok = com -> line_tokens [ i ] ;
3119+ rbs_token_t tok = rbs_buffer_get ( com -> line_tokens , i , rbs_token_t ) ;
31203120
31213121 const char * comment_start = parser -> rbs_lexer_t -> string .start + tok .range .start .byte_pos + hash_bytes ;
31223122 size_t comment_bytes = RBS_RANGE_BYTES (tok .range ) - hash_bytes ;
@@ -3160,43 +3160,29 @@ static rbs_comment_t *comment_get_comment(rbs_comment_t *com, int line) {
31603160}
31613161
31623162static void comment_insert_new_line (rbs_allocator_t * allocator , rbs_comment_t * com , rbs_token_t comment_token ) {
3163- if (com -> line_tokens_count == com -> line_tokens_capacity ) {
3164- size_t old_size = com -> line_tokens_capacity ;
3165- size_t new_size = old_size * 2 ;
3166- com -> line_tokens_capacity = new_size ;
3167-
3168- com -> line_tokens = rbs_allocator_realloc (
3169- allocator ,
3170- com -> line_tokens ,
3171- sizeof (rbs_token_t ) * old_size ,
3172- sizeof (rbs_token_t ) * new_size ,
3173- rbs_token_t
3174- );
3175- }
3163+ rbs_buffer_append_value (allocator , & com -> line_tokens , & comment_token , rbs_token_t );
31763164
3177- com -> line_tokens [ com -> line_tokens_count ++ ] = comment_token ;
3165+ com -> line_tokens_count ++ ;
31783166 com -> end = comment_token .range .end ;
31793167}
31803168
31813169static rbs_comment_t * alloc_comment (rbs_allocator_t * allocator , rbs_token_t comment_token , rbs_comment_t * last_comment ) {
31823170 rbs_comment_t * new_comment = rbs_allocator_alloc (allocator , rbs_comment_t );
31833171
3184- size_t initial_line_capacity = 10 ;
3185-
3186- rbs_token_t * tokens = rbs_allocator_calloc (allocator , initial_line_capacity , rbs_token_t );
3187- tokens [0 ] = comment_token ;
3188-
31893172 * new_comment = (rbs_comment_t ) {
31903173 .start = comment_token .range .start ,
31913174 .end = comment_token .range .end ,
31923175
3193- .line_tokens_capacity = initial_line_capacity ,
3194- .line_tokens_count = 1 ,
3195- .line_tokens = tokens ,
3176+ .line_tokens_count = 0 ,
3177+ .line_tokens = { 0 },
31963178
31973179 .next_comment = last_comment ,
31983180 };
31993181
3182+ size_t initial_line_size = 10 ;
3183+ rbs_buffer_init_with_capacity (allocator , & new_comment -> line_tokens , initial_line_size * sizeof (rbs_token_t ));
3184+ comment_insert_new_line (allocator , new_comment , comment_token );
3185+
32003186 return new_comment ;
32013187}
32023188
0 commit comments