From e28968dbe3720489d60af1c995846f372127b7bd Mon Sep 17 00:00:00 2001 From: Alessio Lombardi Date: Fri, 3 Apr 2020 19:48:48 +0100 Subject: [PATCH] Final iteration on proposed changes. This has been profiled as described in: https://github.com/BHoM/BHoM_Engine/issues/1119#issuecomment-608598656 --- Diffing_Engine/Convert/ToDiffingByteArray.cs | 5 ---- Diffing_Engine/Convert/ToDiffingJson.cs | 29 ++------------------ 2 files changed, 2 insertions(+), 32 deletions(-) diff --git a/Diffing_Engine/Convert/ToDiffingByteArray.cs b/Diffing_Engine/Convert/ToDiffingByteArray.cs index 1384c1715..4c523af2d 100644 --- a/Diffing_Engine/Convert/ToDiffingByteArray.cs +++ b/Diffing_Engine/Convert/ToDiffingByteArray.cs @@ -63,15 +63,10 @@ public static byte[] ToDiffingByteArray(this object obj, List fieldsToIg if (fieldsToIgnore == null || fieldsToIgnore.Count == 0) return BsonExtensionMethods.ToBson(obj); - string objStr = ToDiffingJson(obj, fieldsToIgnore); BsonDocument objDoc = BsonDocument.Parse(objStr); - //fieldsToIgnore.ForEach(propName => - // objDoc.Remove(propName) - //); - return BsonExtensionMethods.ToBson(objDoc); } diff --git a/Diffing_Engine/Convert/ToDiffingJson.cs b/Diffing_Engine/Convert/ToDiffingJson.cs index ae4b3cfa6..37f999a42 100644 --- a/Diffing_Engine/Convert/ToDiffingJson.cs +++ b/Diffing_Engine/Convert/ToDiffingJson.cs @@ -46,38 +46,13 @@ public static partial class Convert ///**** Public Methods ****/ ///***************************************************/ - public static string ToDiffingJson(this object obj, PropertyInfo[] fieldsToNullify) - { - List propList = fieldsToNullify.ToList(); - if (propList == null && propList.Count == 0) - return BH.Engine.Serialiser.Convert.ToJson(obj); - - List propNames = new List(); - propList.ForEach(prop => propNames.Add(prop.Name)); - return ToDiffingJson(obj, propNames); - } - - ///***************************************************/ - public static string ToDiffingJson(this object obj, List fieldsToRemove) { if (fieldsToRemove == null && fieldsToRemove.Count == 0) return BH.Engine.Serialiser.Convert.ToJson(obj); - Stopwatch sw = Stopwatch.StartNew(); - string jsonObj = BH.Engine.Serialiser.Convert.ToJson(obj); - sw.Stop(); - - long timespan1 = sw.ElapsedMilliseconds; - - sw = Stopwatch.StartNew(); - jsonObj = JsonConvert.SerializeObject(obj); - sw.Stop(); - - long timespan2 = sw.ElapsedMilliseconds; - - - + string jsonObj = JsonConvert.SerializeObject(obj); + // Sets fields to be ignored as null, without altering the tree. List regexes = new List();