/// <summary> /// Tests the and create implicit object. /// </summary> /// <param name="node">The node.</param> /// <param name="values">The values.</param> private void testAndCreateImplicitObject(MemoryCollectorNode node, HashSet <Value> values) { if (node.HasNewImplicitObject) { ObjectValue value = Snapshot.MemoryAssistant.CreateImplicitObject(); values.Add(value); IObjectValueContainerBuilder objectValues = Structure.GetObjects(node.TargetIndex).Builder(Structure); objectValues.Add(value); Structure.SetObjects(node.TargetIndex, objectValues.Build(Structure)); IObjectDescriptor oldDescriptor = Structure.GetDescriptor(value); IObjectDescriptorBuilder builder = oldDescriptor.Builder(Structure); foreach (var newChild in node.ImplicitObjectNode.UndefinedChildren) { string childName = newChild.Item1; MemoryCollectorNode childNode = newChild.Item2; MemoryIndex index = ObjectIndex.Create(value, childName); childNode.TargetIndex = index; builder.AddIndex(childName, index); } IObjectDescriptor newDescriptor = builder.Build(Structure); Structure.SetDescriptor(value, newDescriptor); enqueueChildNodes(node.ImplicitObjectNode); } }
/// <summary> /// Deeply copies the specified source index into target index. /// </summary> /// <param name="sourceIndex">Index of the source.</param> /// <param name="targetIndex">Index of the target.</param> public void Copy(MemoryIndex sourceIndex, MemoryIndex targetIndex) { if (!sourceIndex.IsPrefixOf(targetIndex) && !targetIndex.IsPrefixOf(sourceIndex)) { var writeablestrucutre = snapshot.Structure.Writeable; MemoryEntry entry = SnapshotDataUtils.GetMemoryEntry(snapshot, snapshot.CurrentData.Readonly, sourceIndex); CopyWithinSnapshotVisitor visitor = new CopyWithinSnapshotVisitor(snapshot, this, targetIndex); visitor.VisitMemoryEntry(entry); if (isMust && visitor.GetValuesCount() == 1 && objectValues.Count == 1) { IObjectValueContainerBuilder objectsValues = snapshot.Structure.Readonly.GetObjects(targetIndex).Builder(writeablestrucutre); ObjectValue value = objectValues.First(); objectsValues.Add(value); writeablestrucutre.SetObjects(targetIndex, objectsValues.Build(writeablestrucutre)); } else if (objectValues.Count > 0) { IObjectValueContainerBuilder objectsValues = snapshot.Structure.Readonly.GetObjects(targetIndex).Builder(writeablestrucutre); foreach (ObjectValue value in objectValues) { objectsValues.Add(value); } writeablestrucutre.SetObjects(targetIndex, objectsValues.Build(writeablestrucutre)); } if (!isMust) { visitor.AddValue(snapshot.UndefinedValue); } snapshot.CopyAliases(sourceIndex, targetIndex, isMust); snapshot.Data.Writeable.SetMemoryEntry(targetIndex, visitor.GetCopiedEntry()); } }