From 04d46ca129b55711626c8cd2270a3943c69b919b Mon Sep 17 00:00:00 2001 From: Ben Rog-Wilhelm Date: Wed, 2 Oct 2024 02:04:47 -0500 Subject: [PATCH] Fix several Clone pathways that would incorrectly Record objects with a TreatAsValuelike converter, also improving performance. --- CHANGELOG.md | 6 +++++- src/Serialization.cs | 2 +- src/WriterClone.cs | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0fb4cb5e..3d28105a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,8 +10,12 @@ All notable changes to this project will be documented in this file. ### Breaking * Dec doesn't guarantee what order Decs are initialized in, and it still doesn't . . . but it was *pretty consistent*, and boy, did the above change seriously scramble the order they tend to get initialized in! If you have load dependencies, even if you don't realize that you do, don't be surprised if stuff breaks. Future versions of Dec might include a Dev Mode that intentionally randomizes load order (within the bounds of dependencies) to help catch these issues. +### Fixed +* Several Clone pathways that would incorrectly Record objects with a TreatAsValuelike converter. + ### Improved -* Clone performance on Dictionaries with asymmetrical copy-as-valuelike parameters. +* Clone performance on Dictionaries with asymmetrical clone-as-valuelike parameters. +* General Clone performance regarding asymmetrical clone-as-valuelike parameters. ## [v0.7.1] diff --git a/src/Serialization.cs b/src/Serialization.cs index 62fd21e6..282aaec3 100644 --- a/src/Serialization.cs +++ b/src/Serialization.cs @@ -1843,7 +1843,7 @@ internal static void ComposeElement(WriterNode node, object value, Type fieldTyp // Now we have things that *could* be references, but aren't. - if (node.AllowCloning && valType.GetCustomAttribute() != null) + if (node.AllowCloning && UtilType.CanBeCloneCopied(valType)) { node.WriteCloneCopy(value); diff --git a/src/WriterClone.cs b/src/WriterClone.cs index 16356672..543fe5f0 100644 --- a/src/WriterClone.cs +++ b/src/WriterClone.cs @@ -175,7 +175,7 @@ private void CreateResult(bool sharable) // this needs to deal with anything that has complicated constructor behavior var originalType = original.GetType(); bool done = false; - if (originalType.GetCustomAttribute() != null) + if (UtilType.CanBeCloneCopied(originalType)) { // okay result = original;