Ruby 4.1.0dev (2026-09-07 revision 11ce3778c6eacc10897729314e5ab3bed7830971)
line_offset_list.h
1#ifndef PRISM_INTERNAL_LINE_OFFSET_LIST_H
2#define PRISM_INTERNAL_LINE_OFFSET_LIST_H
3
5
6#include "prism/arena.h"
8
9/* Initialize a new line offset list with the given capacity. */
10void pm_line_offset_list_init(pm_arena_t *arena, pm_line_offset_list_t *list, size_t capacity);
11
12/* Clear out the offsets that have been appended to the list. */
13void pm_line_offset_list_clear(pm_line_offset_list_t *list);
14
15/* Append a new offset to the list (slow path with resize). */
16void pm_line_offset_list_append_slow(pm_arena_t *arena, pm_line_offset_list_t *list, uint32_t cursor);
17
18/* Append a new offset to the list. */
19static PRISM_FORCE_INLINE void
20pm_line_offset_list_append(pm_arena_t *arena, pm_line_offset_list_t *list, uint32_t cursor) {
21 if (list->size < list->capacity) {
22 list->offsets[list->size++] = cursor;
23 } else {
24 pm_line_offset_list_append_slow(arena, list, cursor);
25 }
26}
27
28/*
29 * Returns the line of the given offset. If the offset is not in the list, the
30 * line of the closest offset less than the given offset is returned.
31 */
32int32_t pm_line_offset_list_line(const pm_line_offset_list_t *list, uint32_t cursor, int32_t start_line);
33
34#endif
A bump allocator for the prism parser.
#define PRISM_FORCE_INLINE
Force a function to be inlined at every call site.
A list of byte offsets of newlines in a string.
A list of offsets of the start of lines in a string.
uint32_t * offsets
The list of offsets.
size_t size
The number of offsets in the list.
size_t capacity
The capacity of the list that has been allocated.