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

Refactoring by using isa #161

Merged
merged 2 commits into from
Jun 12, 2024
Merged

Refactoring by using isa #161

merged 2 commits into from
Jun 12, 2024

Conversation

Paalon
Copy link
Contributor

@Paalon Paalon commented Jun 12, 2024

Change direct comparisons of types typeof(x) == ConcreteType to using x isa ConcreteType. Especially, isa(x, Union{A, B, C}) is better than in(typeof(x), [A, B, C]) in terms of performance.

Paalon added a commit to Paalon/YAML.jl that referenced this pull request Jun 12, 2024
`peek(stream.input)` is a token instance, so it should be `in(typeof(peek(stream.input)), [A, B, C, D]`.
However, it is better to use `isa` and `Union`, as I mentioned in
JuliaData#161.
Copy link
Collaborator

@kescobo kescobo left a comment

Choose a reason for hiding this comment

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

👍 Thank you for doing all of this cleanup! It's long overdue

kescobo added a commit that referenced this pull request Jun 12, 2024
* Fix a bug in `parse_document_content`.

`peek(stream.input)` is a token instance, so it should be `in(typeof(peek(stream.input)), [A, B, C, D]`.
However, it is better to use `isa` and `Union`, as I mentioned in
#161.

* Update src/parser.jl

Co-authored-by: Kevin Bonham <kevbonham@gmail.com>

* Add a test.

---------

Co-authored-by: Kevin Bonham <kevbonham@gmail.com>
@GunnarFarneback
Copy link
Contributor

For what it's worth, in(typeof(x), (A, B, C)) with a a tuple instead of a vector is as fast as a union, but this code might have been written in the ancient bad times when tuples still had horrible performance.

Regardless I fully agree with changing all of this to isa.

@kescobo
Copy link
Collaborator

kescobo commented Jun 12, 2024

but this code might have been written in the ancient bad times

Indeed
image

@kescobo kescobo merged commit 3f35981 into JuliaData:master Jun 12, 2024
20 checks passed
@Paalon Paalon deleted the refactor-isa-2 branch June 12, 2024 21:59
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