-
Notifications
You must be signed in to change notification settings - Fork 254
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
Update the Rust's brainfuck implementation #325
Conversation
More idiomatic code, and formatting with `rustfmt`. The most important change was in the `Tape` impl: * `mov()` reallocs only once per call; * `get()` and `inc()` uses unchecked indexing because the check is already done in `mov()`
On my machine the improvement was ~2.6 seconds with |
Can I use a an external crate in this implementation? I want to use an arena allocator to alloc the Loop ops. all at once. |
I not think this is needed, because parse is 0.01% time of benchmark, main heavy operation is run. |
Because of the strong typing, the `mov()` was doing many lossy casts which the C and C++ versions don't; the D version uses specific variants too. Besides, the value was always -1 or 1, so it is more idiomatic this way.
On the last commit the improvement was ~2.4 seconds with |
Seems good to me. "unsafe" usage is totally fine here as it's not like the code is somehow unsafe, but rather Rust creators decides to force developers to think twice before accessing elements directly without bounds check. It's not the first time I see the necessity of using "unsafe" constructions in a totally safe code (like in a low-level bits manipulation code). |
More idiomatic code, and formatting with
rustfmt
. The most important change was in theTape
impl:mov()
reallocs only once per call;get()
andinc()
uses unchecked indexing because the check is already done inmov()