Traverse-Research / gpu-allocator

🦀 GPU memory allocator for Vulkan, DirectX 12 and Metal. Written in pure Rust
https://traverse.nl/
Apache License 2.0
380 stars 50 forks source link

Avoid allocating strings when formatting allocation byte-sizes #244

Open nical opened 3 months ago

nical commented 3 months ago

It's not particularly important but while I was adding integration in wgpu for the allocator reports and duplicating a bit of the formatting code in the process, it was rubbing me the wrong way to allocate strings in fmt_bytes when a Display impl could do the same without allocating, so I made the change there. Now I wrote the slightly better version, might as well contribute it back to its original spot!

MarijnS95 commented 3 months ago

Seems quite coincidental that that Rust release notes suggest a nice way of writing this loop too:

https://blog.rust-lang.org/2024/07/25/Rust-1.80.0.html#exclusive-ranges-in-patterns

nical commented 3 months ago

Seems quite coincidental that that Rust release notes suggest a nice way of writing this loop too:

Nice. Is it worth the msrv bump, though? wgpu has to lag a few rustc versions behind, so I'd appreciate if we shelf the nicer version for later.

MarijnS95 commented 3 weeks ago

Nice. Is it worth the msrv bump, though? wgpu has to lag a few rustc versions behind, so I'd appreciate if we shelf the nicer version for later.

Wasn't intending to bump just to use .. (as the article suggests, ..= is already possible with a separate constant), just that it was so well timed :)