Skip to content

Convert TriviasMap (comments) into a Vec #4271

@overlookmotel

Description

@overlookmotel

I think TriviasMap (which contains Comments) could be converted to a Vec.

If I remember right, it was a Vec originally, but was converted to a BTreeMap to work around a problem with comments getting inserted twice when lexer looks ahead and is then rewound.

This problem could still be avoided if it was a Vec. Comments are inserted in source text order, so duplicates could be avoided by checking before pushing whether the last entry's span start is equal or greater than the comment being inserted. If it is, don't push it again.

Seeking by span start could be still performed efficiently with a binary search.

As it's a flat Vec, there would be no significant gain to storing it in arena. std::vec::Vec is fine.

As mentioned in oxc#3580, Trivias could also be stored in Allocator so you can get a &'a Trivias with same lifetime as Program<'a>.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions