Open
Description
Box.box
can cast values of small primitives types to pointer and pass that around directly, instead of allocating space and passing the pointer to that memory.
Extracted from #15562 (comment)
perhaps values smaller than a pointer also don't need an allocation either? Primitive numbers for example:
struct Box(T)
def self.box(object : T) : Void*
{% if T <= Int::Primitive && sizeof(T) <= sizeof(Void*) %}
Pointer(Void).new(object.to_u64!)
{% end %}
end
def self.unbox(pointer : Void*) : T
{% if T <= Int::Primitive && sizeof(T) <= sizeof(Void*) %}
T.new!(pointer.address)
{% end %}
end
end