Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use phf for primitive function lookup #174

Open
dgkf opened this issue Aug 7, 2024 · 0 comments
Open

Use phf for primitive function lookup #174

dgkf opened this issue Aug 7, 2024 · 0 comments
Labels
meta-good first issue Good for newcomers theme-internals Relates to internal operations of the language type-enhancement New feature or request

Comments

@dgkf
Copy link
Owner

dgkf commented Aug 7, 2024

Literal showerthought: why should we have to hash our primitive function names to look up their associated implementation if the list is going to be static? Surely we can build something that doesn't require extra hashing step and can map directly to an index.

And sure enough, it sounds like there's a better static map data structure for this. I found the phf crate after a very non-exaustive search. They even give a very similar example of looking up language keywords.

An added benefit of this is that it can be purely static. No lazy static or LazyLock needed, which should simplify this code even further and avoid the first-time-access cost of building the map (although I'm sure this cost is negligible in the current state).

@dgkf dgkf added type-enhancement New feature or request meta-good first issue Good for newcomers theme-internals Relates to internal operations of the language labels Aug 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
meta-good first issue Good for newcomers theme-internals Relates to internal operations of the language type-enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant