Skip to content

Commit

Permalink
Final iteration on proposed changes.
Browse files Browse the repository at this point in the history
This has been profiled as described in: #1119 (comment)
  • Loading branch information
alelom authored and al-fisher committed Apr 14, 2020
1 parent 8d78fac commit e28968d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 32 deletions.
5 changes: 0 additions & 5 deletions Diffing_Engine/Convert/ToDiffingByteArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,10 @@ public static byte[] ToDiffingByteArray(this object obj, List<string> 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);
}

Expand Down
29 changes: 2 additions & 27 deletions Diffing_Engine/Convert/ToDiffingJson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,38 +46,13 @@ public static partial class Convert
///**** Public Methods ****/
///***************************************************/

public static string ToDiffingJson(this object obj, PropertyInfo[] fieldsToNullify)
{
List<PropertyInfo> propList = fieldsToNullify.ToList();
if (propList == null && propList.Count == 0)
return BH.Engine.Serialiser.Convert.ToJson(obj);

List<string> propNames = new List<string>();
propList.ForEach(prop => propNames.Add(prop.Name));
return ToDiffingJson(obj, propNames);
}

///***************************************************/

public static string ToDiffingJson(this object obj, List<string> 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<Regex> regexes = new List<Regex>();

Expand Down

0 comments on commit e28968d

Please sign in to comment.