Skip to content

perf: use NonNull for null pointer optimization#45

Merged
andylokandy merged 7 commits intoandylokandy:masterfrom
SophieSilver:master
Jun 9, 2025
Merged

perf: use NonNull for null pointer optimization#45
andylokandy merged 7 commits intoandylokandy:masterfrom
SophieSilver:master

Conversation

@SophieSilver
Copy link
Copy Markdown
Contributor

@SophieSilver SophieSilver commented Jun 8, 2025

Use NonNull under the hood. This makes Option<SmallBox<_, _> have the same size as SmallBox<_, _>

resolves #44

Comment thread src/smallbox.rs Outdated
@andylokandy
Copy link
Copy Markdown
Owner

I'm wondering if the addition Layout::align_to is the price to pay... But since align_to is a const function, I believe rustc will figure out a way to eliminate in runtime one day.

Co-authored-by: Andy Lok <andylokandy@hotmail.com>
@andylokandy
Copy link
Copy Markdown
Owner

Thank you @SophieSilver!

@andylokandy andylokandy changed the title Use NonNull for null pointer optimization perf: use NonNull for null pointer optimization Jun 9, 2025
@andylokandy andylokandy merged commit 6c5096f into andylokandy:master Jun 9, 2025
9 checks passed
dilr added a commit to dilr/smallbox that referenced this pull request Aug 2, 2025
dilr added a commit to dilr/smallbox that referenced this pull request Aug 3, 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.

Use NonNull instead of a raw pointer for null pointer optimization

2 participants