This repository has been archived by the owner on Jun 26, 2020. It is now read-only.
Remove null value from Opcode #18
Labels
E-easy
Issues suitable for newcomers to investigate, including Rust newcomers!
After the Rust language designers carefully removed nulls from the language, I went and added my own. It turns out that
Option<T>
is often larger thanT
, and tables with 32-bit or smaller entries can double in size when usingOption<T>
.C-like
Opcode
enumThe
Opcode
enum in the generatedopcodes.rs
file contains an explicit null value:With the current opcodes,
Opcode
is a single byte, butOption<Opcode>
is two bytes. We use the explicit null to indicate the empty slots in a precomputed hash table:This table would double in size if we used
Option<Opcode>
. Since this table is only used by the parser when mapping strings to opcodes, perhaps we should just bite the bullet and use anOption<Opcode>
here. Hopefully, the Rust compiler will soon learn how to represent this sum type efficiently. It's one of the easier nested enum optimizations.Encoding tables also use
NotAnOpcode
currently. These tables are more critical to keep small, but there may be an alternative representation of the empty slots.The text was updated successfully, but these errors were encountered: