Exemplo n.º 1
0
        public void MergeIndexes(MemoryIndex targetIndex, MemoryIndex sourceIndex)
        {
            if (!sourceIndex.IsPrefixOf(targetIndex) && !targetIndex.IsPrefixOf(sourceIndex))
            {
                MergeOperation operation = new MergeOperation(targetIndex);
                operation.Add(targetIndex, targetSnapshot);
                operation.Add(sourceIndex, targetSnapshot);
                operation.IsRoot = true;
                addOperation(operation);

                arrayCount = 2;

                processMerge();
            }
        }
Exemplo n.º 2
0
        /// <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))
            {
                MemoryEntry entry = snapshot.Structure.GetMemoryEntry(sourceIndex);

                CopyWithinSnapshotVisitor visitor = new CopyWithinSnapshotVisitor(this, targetIndex);
                visitor.VisitMemoryEntry(entry);

                if (isMust && visitor.GetValuesCount() == 1 && objectValues.Count == 1)
                {
                    ObjectValueContainerBuilder objectsValues = snapshot.Structure.GetObjects(targetIndex).Builder();

                    ObjectValue value = objectValues.First();
                    objectsValues.Add(value);
                    snapshot.Structure.SetObjects(targetIndex, objectsValues.Build());
                }
                else if (objectValues.Count > 0)
                {
                    ObjectValueContainerBuilder objectsValues = snapshot.Structure.GetObjects(targetIndex).Builder();
                    foreach (ObjectValue value in objectValues)
                    {
                        objectsValues.Add(value);
                    }
                    snapshot.Structure.SetObjects(targetIndex, objectsValues.Build());
                }

                if (!isMust)
                {
                    visitor.AddValue(snapshot.UndefinedValue);
                }

                snapshot.CopyAliases(sourceIndex, targetIndex, isMust);

                snapshot.Structure.SetMemoryEntry(targetIndex, visitor.GetCopiedEntry());
            }
        }