@@ -3190,28 +3190,18 @@ static rbs_comment_t *comment_get_comment(rbs_comment_t *com, int line) {
3190
3190
}
3191
3191
3192
3192
static void comment_insert_new_line (rbs_allocator_t * allocator , rbs_comment_t * com , rbs_token_t comment_token ) {
3193
- if (com -> line_count == 0 ) {
3194
- com -> start = comment_token .range .start ;
3195
- }
3196
-
3197
3193
if (com -> line_count == com -> line_size ) {
3198
- if (com -> line_size == 0 ) com -> line_size = 10 ; // Don't get stuck multiplying by 0 forever
3199
-
3200
- if (com -> tokens ) {
3201
- size_t old_size = com -> line_size ;
3202
- size_t new_size = old_size * 2 ;
3203
- com -> line_size = new_size ;
3204
-
3205
- com -> tokens = rbs_allocator_realloc (
3206
- allocator ,
3207
- com -> tokens ,
3208
- sizeof (rbs_token_t ) * old_size ,
3209
- sizeof (rbs_token_t ) * new_size ,
3210
- rbs_token_t
3211
- );
3212
- } else {
3213
- com -> tokens = rbs_allocator_calloc (allocator , com -> line_size , rbs_token_t );
3214
- }
3194
+ size_t old_size = com -> line_size ;
3195
+ size_t new_size = old_size * 2 ;
3196
+ com -> line_size = new_size ;
3197
+
3198
+ com -> tokens = rbs_allocator_realloc (
3199
+ allocator ,
3200
+ com -> tokens ,
3201
+ sizeof (rbs_token_t ) * old_size ,
3202
+ sizeof (rbs_token_t ) * new_size ,
3203
+ rbs_token_t
3204
+ );
3215
3205
}
3216
3206
3217
3207
com -> tokens [com -> line_count ++ ] = comment_token ;
@@ -3221,19 +3211,22 @@ static void comment_insert_new_line(rbs_allocator_t *allocator, rbs_comment_t *c
3221
3211
static rbs_comment_t * alloc_comment (rbs_allocator_t * allocator , rbs_token_t comment_token , rbs_comment_t * last_comment ) {
3222
3212
rbs_comment_t * new_comment = rbs_allocator_alloc (allocator , rbs_comment_t );
3223
3213
3214
+ size_t initial_line_size = 10 ;
3215
+
3216
+ rbs_token_t * tokens = rbs_allocator_calloc (allocator , initial_line_size , rbs_token_t );
3217
+ tokens [0 ] = comment_token ;
3218
+
3224
3219
* new_comment = (rbs_comment_t ) {
3225
3220
.start = comment_token .range .start ,
3226
3221
.end = comment_token .range .end ,
3227
3222
3228
- .line_size = 0 ,
3229
- .line_count = 0 ,
3230
- .tokens = NULL ,
3223
+ .line_size = initial_line_size ,
3224
+ .line_count = 1 ,
3225
+ .tokens = tokens ,
3231
3226
3232
3227
.next_comment = last_comment ,
3233
3228
};
3234
3229
3235
- comment_insert_new_line (allocator , new_comment , comment_token );
3236
-
3237
3230
return new_comment ;
3238
3231
}
3239
3232
0 commit comments