@@ -3116,7 +3116,7 @@ static rbs_ast_comment_t *parse_comment_lines(rbs_parser_t *parser, rbs_comment_
3116
3116
rbs_buffer_init (ALLOCATOR (), & rbs_buffer );
3117
3117
3118
3118
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 ) ;
3120
3120
3121
3121
const char * comment_start = parser -> rbs_lexer_t -> string .start + tok .range .start .byte_pos + hash_bytes ;
3122
3122
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) {
3160
3160
}
3161
3161
3162
3162
static 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 );
3176
3164
3177
- com -> line_tokens [ com -> line_tokens_count ++ ] = comment_token ;
3165
+ com -> line_tokens_count ++ ;
3178
3166
com -> end = comment_token .range .end ;
3179
3167
}
3180
3168
3181
3169
static rbs_comment_t * alloc_comment (rbs_allocator_t * allocator , rbs_token_t comment_token , rbs_comment_t * last_comment ) {
3182
3170
rbs_comment_t * new_comment = rbs_allocator_alloc (allocator , rbs_comment_t );
3183
3171
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
-
3189
3172
* new_comment = (rbs_comment_t ) {
3190
3173
.start = comment_token .range .start ,
3191
3174
.end = comment_token .range .end ,
3192
3175
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 },
3196
3178
3197
3179
.next_comment = last_comment ,
3198
3180
};
3199
3181
3182
+ size_t initial_line_capacity = 10 ;
3183
+ rbs_buffer_init_with_capacity (allocator , & new_comment -> line_tokens , initial_line_capacity * sizeof (rbs_token_t ));
3184
+ comment_insert_new_line (allocator , new_comment , comment_token );
3185
+
3200
3186
return new_comment ;
3201
3187
}
3202
3188
0 commit comments