dropbox / rust-brotli

Brotli compressor and decompressor written in rust that optionally avoids the stdlib
https://dropbox.tech/infrastructure/-broccoli--syncing-faster-by-syncing-less
BSD 3-Clause "New" or "Revised" License
818 stars 83 forks source link

Simplify mem cell alloc usage #207

Closed nyurik closed 5 months ago

nyurik commented 5 months ago

Introduce several helper memory allocation functions to reduce boilerplate code. This will help in the future to further simplify allocation, esp when alloc module becomes part of stdlib. The helper functions allow far simpler usage with a generic type as the first param.

I began with this replacement:

\<([a-zA-Z0-9_]+) as Allocator\<([a-zA-Z0-9_]+)\>\>\:\:AllocatedMemory\:\:default\(\s*\)

with

alloc_default::<$2, $1>()

In a few cases, I was able to use alloc.alloc_cell(...) directly (compiler was able to figure out which type to use automatically).

Afterward, found all conditional allocations and replaced them with alloc_if(condition, ...), and fixed the imports

nyurik commented 5 months ago

@danielrh when you have a chance, please merge this one early on because it might conflict with some other PRs. It should be fairly straight to review, as most changes were search/replaced