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

keyboard: use SmallVec for the Enter event's currently pressed keys #163

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

valpackett
Copy link

The Event enum used string slices referencing stack-allocated Vecs (that were not reused anywhere else).
The lifetime makes it awkward for consumers (no way to e.g. store the Event somewhere) but I doubt
that it was a useful optimization (even if the optimizer can't allocate the Vec directly in the resulting enum,
creating a slice of it is hardly better than moving it: you still write the address and size, just not the capacity).

However, we can use SmallVec (already a dependency of wayland-rs) for an actual optimization:
this will avoid allocating Vec contents if 1-2 keys are held when the surface gets keyboard focus.


Unfortunately this does change the public API (e.g. winit would need to drop a <'_>) — it's possible to add a PhantomData for the lifetime though, but accumulating backwards compat junk on 0.x versions is ehh :/

The Event enum used string slices referencing stack-allocated Vecs (that were not reused anywhere else).
The lifetime makes it awkward for consumers (no way to e.g. store the Event somewhere) but I doubt
that it was a useful optimization (even if the optimizer can't allocate the Vec directly in the resulting enum,
creating a slice of it is hardly better than moving it: you still write the address and size, just not the capacity).

However, we can use SmallVec (already a dependency of wayland-rs) for an actual optimization:
this will avoid allocating Vec contents if 1-2 keys are held when the surface gets keyboard focus.
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.

None yet

1 participant