@@ -3208,7 +3208,7 @@ static rbs_ast_comment_t *parse_comment_lines(rbs_parser_t *parser, rbs_comment_
3208
3208
rbs_buffer_init (ALLOCATOR (), & rbs_buffer );
3209
3209
3210
3210
for (size_t i = 0 ; i < com -> line_tokens_count ; i ++ ) {
3211
- rbs_token_t tok = com -> line_tokens [ i ] ;
3211
+ rbs_token_t tok = rbs_buffer_get ( com -> line_tokens , i , rbs_token_t ) ;
3212
3212
3213
3213
const char * comment_start = parser -> rbs_lexer_t -> string .start + tok .range .start .byte_pos + hash_bytes ;
3214
3214
size_t comment_bytes = RBS_RANGE_BYTES (tok .range ) - hash_bytes ;
@@ -3252,43 +3252,29 @@ static rbs_comment_t *comment_get_comment(rbs_comment_t *com, int line) {
3252
3252
}
3253
3253
3254
3254
static void comment_insert_new_line (rbs_allocator_t * allocator , rbs_comment_t * com , rbs_token_t comment_token ) {
3255
- if (com -> line_tokens_count == com -> line_tokens_capacity ) {
3256
- size_t old_size = com -> line_tokens_capacity ;
3257
- size_t new_size = old_size * 2 ;
3258
- com -> line_tokens_capacity = new_size ;
3259
-
3260
- com -> line_tokens = rbs_allocator_realloc (
3261
- allocator ,
3262
- com -> line_tokens ,
3263
- sizeof (rbs_token_t ) * old_size ,
3264
- sizeof (rbs_token_t ) * new_size ,
3265
- rbs_token_t
3266
- );
3267
- }
3255
+ rbs_buffer_append_value (allocator , & com -> line_tokens , & comment_token , rbs_token_t );
3268
3256
3269
- com -> line_tokens [ com -> line_tokens_count ++ ] = comment_token ;
3257
+ com -> line_tokens_count ++ ;
3270
3258
com -> end = comment_token .range .end ;
3271
3259
}
3272
3260
3273
3261
static rbs_comment_t * alloc_comment (rbs_allocator_t * allocator , rbs_token_t comment_token , rbs_comment_t * last_comment ) {
3274
3262
rbs_comment_t * new_comment = rbs_allocator_alloc (allocator , rbs_comment_t );
3275
3263
3276
- size_t initial_line_capacity = 10 ;
3277
-
3278
- rbs_token_t * tokens = rbs_allocator_calloc (allocator , initial_line_capacity , rbs_token_t );
3279
- tokens [0 ] = comment_token ;
3280
-
3281
3264
* new_comment = (rbs_comment_t ) {
3282
3265
.start = comment_token .range .start ,
3283
3266
.end = comment_token .range .end ,
3284
3267
3285
- .line_tokens_capacity = initial_line_capacity ,
3286
- .line_tokens_count = 1 ,
3287
- .line_tokens = tokens ,
3268
+ .line_tokens_count = 0 ,
3269
+ .line_tokens = { 0 },
3288
3270
3289
3271
.next_comment = last_comment ,
3290
3272
};
3291
3273
3274
+ size_t initial_line_capacity = 10 ;
3275
+ rbs_buffer_init_with_capacity (allocator , & new_comment -> line_tokens , initial_line_capacity * sizeof (rbs_token_t ));
3276
+ comment_insert_new_line (allocator , new_comment , comment_token );
3277
+
3292
3278
return new_comment ;
3293
3279
}
3294
3280
0 commit comments