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

Refactor response bools to bitflags #3905

Closed
wants to merge 5 commits into from

Conversation

BSFishy
Copy link

@BSFishy BSFishy commented Jan 27, 2024

This PR focuses primarily on adding the bitflags dependency and converting the immediate bools in Response into bitflags. I'm mainly looking for style feedback before diving into the [bool; NUM_POINTER_BUTTONS] and Sense bitflags.

Tested manually with some basic sanity testing as well as cargo test.

Partially fixes #3862

Signed-off-by: Matt Provost <mattprovost6@gmail.com>
@@ -6,6 +6,41 @@ use crate::{

// ----------------------------------------------------------------------------

bitflags::bitflags! {
/// The state of a widget.
Copy link
Author

Choose a reason for hiding this comment

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

I have no idea what would be good docs for this struct. Feedback would be appreciated :)

@@ -6,6 +6,41 @@ use crate::{

// ----------------------------------------------------------------------------

bitflags::bitflags! {
Copy link
Author

Choose a reason for hiding this comment

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

Is this the right place to put this struct?

Signed-off-by: Matt Provost <mattprovost6@gmail.com>
Signed-off-by: Matt Provost <mattprovost6@gmail.com>
Comment on lines +1090 to +1092
if sense.click && res.hovered() && res.is_pointer_button_down_on() {
if let Some(click) = click {
let clicked = res.hovered && res.is_pointer_button_down_on;
let clicked = res.hovered() && res.is_pointer_button_down_on();
Copy link
Author

Choose a reason for hiding this comment

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

Since clicked now has more complexity associated with it (performing bitwise operations to check if the bitflags contain those 2), should it be moved out of the 2 ifs and just reused? Or is the added cycles negligible to performance?

Copy link
Owner

Choose a reason for hiding this comment

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

The optimizer should take care of it for you if fn hovered is marked #[inline]

Copy link
Owner

Choose a reason for hiding this comment

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

You can always run cargo bench to check

@BSFishy
Copy link
Author

BSFishy commented Jan 27, 2024

Also, should bitflags be added to the Dependencies section of the README?

Signed-off-by: Matt Provost <mattprovost6@gmail.com>
@emilk
Copy link
Owner

emilk commented Jan 29, 2024

Also, should bitflags be added to the Dependencies section of the README?

Yes

Copy link
Owner

@emilk emilk left a comment

Choose a reason for hiding this comment

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

looking good at a quick glance!

@@ -92,6 +92,7 @@ backtrace = { version = "0.3", optional = true }
## Enable this when generating docs.
document-features = { version = "0.2", optional = true }

bitflags = "2.4"
Copy link
Owner

Choose a reason for hiding this comment

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

This should move up. It is currently under the #! ### Optional dependencies heading

Comment on lines +1090 to +1092
if sense.click && res.hovered() && res.is_pointer_button_down_on() {
if let Some(click) = click {
let clicked = res.hovered && res.is_pointer_button_down_on;
let clicked = res.hovered() && res.is_pointer_button_down_on();
Copy link
Owner

Choose a reason for hiding this comment

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

You can always run cargo bench to check

@@ -6,6 +6,44 @@ use crate::{

// ----------------------------------------------------------------------------

bitflags::bitflags! {
/// The state of a widget.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
Copy link
Owner

Choose a reason for hiding this comment

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

I don't think it makes sense for this to implement PartialOrd and Ord

@emilk
Copy link
Owner

emilk commented Jan 6, 2025

@emilk emilk closed this Jan 6, 2025
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.

Performance: replace bools in Response with bit-sets
2 participants