Skip to content

Templated-data-only GjsAutoPointer (and use it more around)

Marco Trevisan requested to merge 3v1n0/gjs:templated-gjs-autopointer into master

I had this idea for some time, but given that this comment !494 (comment 908662) was enough to trigger me to actually do this...


We introduced GjsAutoPointer as part of commit dab3c7d0, to avoid duplication of the same code everywhere, and that served us well to create multiple smart pointer types, however since we were relying on std::unique_ptr, all the times we created a pointer with a custom destructor, we were allocating 8bits more, and this can be sensitive when used around in wrappers.

However, since we are already constructing the auto-pointers passing all these information as template (generating some custom code, for sure), we can just rely on the template parameters also for the destructor, and so ensuring that the struct size always matches the wrapped pointer, removing all the overhead.

This will allow to use GjsAutoPointer's everywhere without increasing the size of the wrapped objects.

As per this being all new (even though the API is mainly inspired to unique_ptr), adding various unit tests to ensure we behave correctly.


Also introduced real copy constructors (when we can) and FINALLY, real static checks on the function pointers that will ensure that we won't try to copy an object that has no ref_func set.

As per this, use it a bit more around given we won't include any extra overhead...

Merge request reports