Skip to content

Commit

Permalink
Reduce runtime expenses for composing dictEntriesOfInterest
Browse files Browse the repository at this point in the history
  • Loading branch information
Viir committed Apr 10, 2022
1 parent e0960e2 commit b28dcfe
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions implement/read-memory-64-bit/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1153,18 +1153,16 @@ UITreeNode[] ReadChildren()
.Where(entry => !((entry.value as UITreeNode.DictEntryValueGenericRepresentation)?.pythonObjectTypeName == "NoneType"))
.ToArray();

var dictEntriesOfInterestJObject =
new System.Text.Json.Nodes.JsonObject(
dictEntriesOfInterestLessNoneType.Select(dictEntry =>
new KeyValuePair<string, System.Text.Json.Nodes.JsonNode?>
(dictEntry.key,
System.Text.Json.Nodes.JsonNode.Parse(SerializeMemoryReadingNodeToJson(dictEntry.value)))));
var dictEntriesOfInterestDict =
dictEntriesOfInterestLessNoneType.Aggregate(
seed: ImmutableDictionary<string, object>.Empty,
func: (dict, entry) => dict.SetItem(entry.key, entry.value));

return new UITreeNode
(
pythonObjectAddress: nodeAddress,
pythonObjectTypeName: pythonObjectTypeName,
dictEntriesOfInterest: dictEntriesOfInterestJObject,
dictEntriesOfInterest: dictEntriesOfInterestDict,
otherDictEntriesKeys: otherDictEntriesKeys.ToArray(),
children: ReadChildren()?.Where(child => child != null)?.ToArray()
);
Expand Down Expand Up @@ -1444,7 +1442,7 @@ public class PyObject
public record UITreeNode(
ulong pythonObjectAddress,
string pythonObjectTypeName,
System.Text.Json.Nodes.JsonObject dictEntriesOfInterest,
IReadOnlyDictionary<string, object> dictEntriesOfInterest,
string[] otherDictEntriesKeys,
IReadOnlyList<UITreeNode> children)
{
Expand Down

0 comments on commit b28dcfe

Please sign in to comment.