Skip to content

Use an array instead of a switch in token_kind_name#63

Open
RHL120 wants to merge 1 commit into
tsoding:masterfrom
RHL120:array_tok
Open

Use an array instead of a switch in token_kind_name#63
RHL120 wants to merge 1 commit into
tsoding:masterfrom
RHL120:array_tok

Conversation

@RHL120

@RHL120 RHL120 commented Feb 12, 2023

Copy link
Copy Markdown

This change removes 19 lines of code and gives the function a (negligible) speed improvement .

@kasimeka

Copy link
Copy Markdown

this removes the concrete link between each Token_kind value and the name that represents it, which makes the code less readable and less extensible. the data structure that would be an improvement is a map, but that's pretty overkill

@RHL120

RHL120 commented Feb 12, 2023

Copy link
Copy Markdown
Author

this removes the concrete link between each Token_kind value and the name that represents it, which makes the code less readable and less extensible. the data structure that would be an improvement is a map, but that's pretty overkill

Yeah I guess there is a trade off here, I would chose the array method but the maintainer might disagree with me.
Thanks for the review!

@BillKek

BillKek commented Feb 12, 2023

Copy link
Copy Markdown
Contributor

Speed improvement makes by the compiler itself, IMHO. And UNREACHABLE feature lost.

@RHL120

RHL120 commented Feb 12, 2023

Copy link
Copy Markdown
Author

Speed improvement makes by the compiler itself, IMHO. And UNREACHABLE feature lost.

I can put it back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants