Closed frebib closed 3 years ago
Had to rework the implementation slightly (one of the existing tests was failing, showing a flaw in my patch!). It now takes arrays into account too and doesn't panic now. Reworked the tests too. Good for review again
Sorry for the delay! All merged now, thanks =D
Map and list types are now unconditionally initialised during an Into() call to ensure that the only data within them after the operation is that added by the Into() function.
Prior to this change, map/list types would likely not be cleared prior to the data being inserted into them with a few exceptions. Nil pointers or maps/lists that were not sufficient in capacity would be reinitialised and used to replace the existing backing data store. In some cases this wouldn't occur meaning any residual data existing in the container before the Into() call could persist after the data copy completes. This behaviour is wildly inconsistent and not ideal in the vast majority of cases. It should be assumed that the Into() call will preserve nothing and always produce a consistent and deterministic output.
One bonus of this change is that Into() will now correctly set empty lists to an empty slice instead of leaving a nil pointer, and the same is likely true for maps too. It allows the user to distinguish between nil and empty container types, as in certain cases those semantics can make a difference.
Signed-off-by: Joe Groocock me@frebib.net