Details
-
Enhancement
-
Resolution: Unresolved
-
Major
-
None
-
None
-
None
-
High
Description
Implement a cloner configuration option to pass by reference whenever possible.
The general behavioral contract would be to only clone an object when its type class is not equal to the cloned type class for that object, or if any of its contents (fields or array members) fail this test.
Because object graphs may be circular, a simple recursive determination cannot be used because the decision to clone an object cannot be made until all of its contents are evaluated. Thus the decision for each object in the graph has to be deferred until all objects have been visited, meaning that cloning must occur in two passes: the first pass to map the object graph and make simple clone/no clone determinations, and the second pass to make the final determination and instantiate and populate the object graph.
There is a more optimal recursive solution for non-cyclic object graphs which is similar to the existing algorithm. It would be possible to use a configuration option to establish that the optimal algorithm is preferred (which consequently will cause cyclic object graphs to fail).