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

minor refactor: use built-in option methods instead of try_for_opt! macro #140

Merged
merged 1 commit into from
Feb 7, 2024

Conversation

SKalt
Copy link
Contributor

@SKalt SKalt commented Feb 7, 2024

I was reading through the code and had to check what try_for_opt! did. I factored the macro into built-in option methods to improve my comprehension of the code. I recognize this is a minor refactor that wasn't requested; please feel free to close this PR if it's too minor or it decreases readability.

In any case, thanks for writing ttf-parser! I'm enjoying using it.

if target_sub.or(next_sub).is_none() {
return 0.0;
};
let d = f32::from(target_sub.unwrap()) / f32::from(next_sub.unwrap());
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would prefer:

let d = if let (Some(target_sub), Some(next_sub)) = (target_sub, next_sub) {
    f32::from(target_sub) / f32::from(next_sub)
} else {
    return 0.0
};

@RazrFalcon
Copy link
Collaborator

Thanks! That's a good change. I do not like using macros in general. Those are just some old left-overs.

@RazrFalcon
Copy link
Collaborator

Looks like you have removed your checked_sub lines as well. They should stay.

The `try_opt_or!` macro slightly shortened some
`map(...).unwrap_or(...)` logic in `./lib.rs`, and
some longer `if _.is_none() { return }` logic in
`./tables/gvar.rs`. I had to do some code searching
to figure out what `try_opt_or!` did, so I refactored
it for my own comprension.
@SKalt
Copy link
Contributor Author

SKalt commented Feb 7, 2024

Whoops. I fixed that and rebased my changes into a single commit, which I re-checked with cargo check and cargo fmt locally.

@RazrFalcon RazrFalcon merged commit 2192d3e into harfbuzz:master Feb 7, 2024
2 checks passed
@RazrFalcon
Copy link
Collaborator

All good. Thanks!

@SKalt SKalt deleted the deprecate-try_opt_or-macro branch February 7, 2024 19:18
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.

2 participants