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

Narrow down enum types #431

Merged
merged 13 commits into from
Dec 25, 2023
Merged

Narrow down enum types #431

merged 13 commits into from
Dec 25, 2023

Conversation

Casheeew
Copy link
Member

This change narrows down the number type to an union of number literals to represent an enum. It also changes the if else matching pattern to switch statements to more closely match the enum matching patterns in other programming languages, as well as already existing code inside the project.

Part of the movement towards type safety.

@Casheeew Casheeew requested a review from a team as a code owner December 23, 2023 00:27
Copy link

github-actions bot commented Dec 23, 2023

✔️ No visual differences introduced by this PR.

View Playwright Report (note: open the "playwright-report" artifact)

ext/js/dom/dom-text-scanner.js Outdated Show resolved Hide resolved
ext/js/language/text-scanner.js Show resolved Hide resolved
.eslintrc.json Outdated Show resolved Hide resolved
Copy link
Collaborator

@djahandarie djahandarie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for making the improvements! LGTM. Hopefully we can turn on that exhaustiveness lint eventually

@djahandarie djahandarie added this pull request to the merge queue Dec 25, 2023
Merged via the queue into yomidevs:master with commit bdaa77f Dec 25, 2023
5 checks passed
@Casheeew Casheeew deleted the dev3 branch December 25, 2023 08:44

if (--remainder <= 0) { break; }
}
({done, lineHasWhitespace, lineHasContent, content, offset, remainder, newlines} = this._checkCharacterBackward(char, charAttributes, seekTextNoteDetails));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My comment is a bit late on this, but these sub-functions should probably just be modifying the seekTextNoteDetails value that is passed into it. As it stands right now, it's repeatedly constructing and destructuring a large structure in a high-bandwidth code-path, which is probably not great. Obviously this project doesn't have performance tests currently, so I don't have hard data to back this up, but I'd imagine that this is likely less efficient.

One of the reasons why this code path was originally somewhat messy was because it was a highly-used function. That's why it was doing the weird thing where it would assign all of the member fields to local variables first, and then restore them after: for (presumably) faster access in a loop. However, now that that effect is no longer being used, there is really no reason to do that, and instead the member fields should be used directly.

This is what it would look like:
https://github.com/toasted-nutbread/yomichan/commits/simplify-dom-text-scanner/

But I'm also not sure if there's a strong benefit of making that change vs just leaving the loop in the function. There's probably a lot of code locality and caching stuff that goes on in JS there, so it's hard to say what is the best way to do this in the long run without performance benchmarks.

@Casheeew Casheeew mentioned this pull request Dec 27, 2023
@djahandarie djahandarie added the kind/meta The issue or PR is meta label Dec 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/meta The issue or PR is meta
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants