private bool compareData(MemoryIndex index) { MemoryEntry newEntry = null; if (!newData.Readonly.TryGetMemoryEntry(index, out newEntry)) { newEntry = snapshot.EmptyEntry; } MemoryEntry oldEntry = null; if (!oldData.Readonly.TryGetMemoryEntry(index, out oldEntry)) { oldEntry = snapshot.EmptyEntry; } if (ValueUtils.CompareMemoryEntries(newEntry, oldEntry)) { return(true); } else if (newEntry.Count > simplifyLimit) { MemoryEntry simplifiedEntry = assistant.Simplify(newEntry); MemoryEntry entry = setNewMemoryEntry(index, newEntry, simplifiedEntry); return(ValueUtils.CompareMemoryEntries(entry, oldEntry)); } else { return(false); } }
private void widenAndSimplifyData() { List <MemoryIndex> indexes = new List <MemoryIndex>(); CollectionMemoryUtils.AddAll(indexes, newData.Readonly.ReadonlyChangeTracker.IndexChanges); var previousTracker = newData.Readonly.ReadonlyChangeTracker.PreviousTracker; var currentTracker = newData.Writeable.WriteableChangeTracker; foreach (MemoryIndex index in indexes) { MemoryEntry newEntry = getMemoryEntryOrEmpty(index, newData.Readonly); MemoryEntry accEntryValue = newEntry; if (newEntry != null && newEntry.Count > simplifyLimit) { MemoryEntry simplifiedEntry = assistant.Simplify(newEntry); accEntryValue = simplifiedEntry; } MemoryEntry oldEntry = getMemoryEntryOrEmpty(index, oldData.Readonly); if (!ValueUtils.CompareMemoryEntries(newEntry, oldEntry)) { MemoryEntry widenedEntry = assistant.Widen(oldEntry, newEntry); accEntryValue = widenedEntry; } if (previousTracker != null) { MemoryEntry previousEntry = getMemoryEntryOrEmpty(index, previousTracker.Container); if (ValueUtils.CompareMemoryEntries(previousEntry, accEntryValue)) { currentTracker.RemoveIndexChange(index); } } if (accEntryValue != newEntry && newEntry != null) { setNewMemoryEntry(index, newEntry, accEntryValue); } } }
/// <summary> /// Simplify data of single memory index if exceeds given simplify limit and compares it with the data inside given data container. /// </summary> /// <param name="oldData">The old data.</param> /// <param name="index">The index.</param> /// <param name="simplifyLimit">The simplify limit.</param> /// <param name="assistant">The assistant.</param> /// <returns>True whether compared data are the same.</returns> public bool DataEqualsAndSimplify(SnapshotData oldData, MemoryIndex index, int simplifyLimit, MemoryAssistantBase assistant) { MemoryEntry newEntry = null; if (!this.IndexData.TryGetValue(index, out newEntry)) { newEntry = EmptyEntry; } MemoryEntry oldEntry = null; if (!oldData.IndexData.TryGetValue(index, out oldEntry)) { oldEntry = EmptyEntry; } if (oldEntry.Equals(newEntry)) { return(true); } else if (newEntry.Count > simplifyLimit) { MemoryIndex testIndex = ControlIndex.Create(".return", 6); if (testIndex.Equals(index)) { } MemoryEntry simplifiedEntry = assistant.Simplify(newEntry); SetMemoryEntry(index, simplifiedEntry); return(oldEntry.Equals(simplifiedEntry)); } else { return(false); } }