Skip to content

Commit f79be8e

Browse files
committed
Switch data_loc over to using a slice
1 parent 73cb157 commit f79be8e

4 files changed

Lines changed: 8 additions & 8 deletions

File tree

ext/prism/extension.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,10 +533,10 @@ parser_magic_comments(const pm_parser_t *parser, VALUE source, bool freeze) {
533533
*/
534534
static VALUE
535535
parser_data_loc(const pm_parser_t *parser, VALUE source, bool freeze) {
536-
if (parser->data_loc.end == NULL) {
536+
if (parser->data_loc.length == 0) {
537537
return Qnil;
538538
} else {
539-
return PARSER_LOCATION_LOC(parser, source, freeze, parser->data_loc);
539+
return parser_location(parser, source, freeze, parser->data_loc.start, parser->data_loc.length);
540540
}
541541
}
542542

include/prism/parser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ struct pm_parser {
722722
* and the rest of the content of the file. This content is loaded into the
723723
* DATA constant when the file being parsed is the main file being executed.
724724
*/
725-
pm_location_t data_loc;
725+
pm_slice_t data_loc;
726726

727727
/** The list of warnings that have been found while parsing. */
728728
pm_list_t warning_list;

src/prism.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10951,8 +10951,8 @@ parser_lex(pm_parser_t *parser) {
1095110951
parser->current.type = PM_TOKEN___END__;
1095210952
parser_lex_callback(parser);
1095310953

10954-
parser->data_loc.start = parser->current.start;
10955-
parser->data_loc.end = parser->current.end;
10954+
parser->data_loc.start = (uint32_t) (parser->current.start - parser->start);
10955+
parser->data_loc.length = (uint32_t) (parser->current.end - parser->current.start);
1095610956

1095710957
LEX(PM_TOKEN_EOF);
1095810958
}
@@ -21707,7 +21707,7 @@ pm_parser_init(pm_parser_t *parser, const uint8_t *source, size_t size, const pm
2170721707
.current = { .type = PM_TOKEN_EOF, .start = source, .end = source },
2170821708
.next_start = NULL,
2170921709
.heredoc_end = NULL,
21710-
.data_loc = { .start = NULL, .end = NULL },
21710+
.data_loc = { 0 },
2171121711
.comment_list = { 0 },
2171221712
.magic_comment_list = { 0 },
2171321713
.warning_list = { 0 },

templates/src/serialize.c.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,11 +232,11 @@ pm_serialize_magic_comment_list(pm_list_t *list, pm_buffer_t *buffer) {
232232

233233
static void
234234
pm_serialize_data_loc(const pm_parser_t *parser, pm_buffer_t *buffer) {
235-
if (parser->data_loc.end == NULL) {
235+
if (parser->data_loc.length == 0) {
236236
pm_buffer_append_byte(buffer, 0);
237237
} else {
238238
pm_buffer_append_byte(buffer, 1);
239-
pm_serialize_location(parser, &parser->data_loc, buffer);
239+
pm_serialize_slice(&parser->data_loc, buffer);
240240
}
241241
}
242242

0 commit comments

Comments
 (0)