mirror of
https://github.com/haven1433/HexManiacAdvance.git
synced 2026-06-02 21:45:13 -05:00
performance improvement: cache data change
Only notify property HasDataChange if the value actually changed. Use a cache to store the old value. Calculating HasDataChange is fast, but updating from HasDataChange notifications can be slow.
This commit is contained in:
parent
788d343357
commit
1b34e440ab
|
|
@ -136,6 +136,7 @@ namespace HavenSoft.HexManiac.Core.ViewModels {
|
|||
|
||||
public void TagAsSaved() {
|
||||
ChangeCompleted();
|
||||
hasDataChangeCache = false;
|
||||
if (TryUpdate(ref undoStackSizeAtSaveTag, undoStack.Count, nameof(IsSaved))) {
|
||||
NotifyPropertyChanged(nameof(HasDataChange));
|
||||
}
|
||||
|
|
@ -149,9 +150,14 @@ namespace HavenSoft.HexManiac.Core.ViewModels {
|
|||
return new StubDisposable { Dispose = () => continueCurrentTransaction = previousValue };
|
||||
}
|
||||
|
||||
private bool hasDataChangeCache;
|
||||
private void OnCurrentTokenDataChanged(object sender, EventArgs e) {
|
||||
if (undoStack.Count == 0) undo.RaiseCanExecuteChanged();
|
||||
NotifyPropertyChanged(nameof(HasDataChange));
|
||||
var hasDataChange = HasDataChange;
|
||||
if (hasDataChange != hasDataChangeCache) {
|
||||
hasDataChangeCache = hasDataChange;
|
||||
NotifyPropertyChanged(nameof(HasDataChange));
|
||||
}
|
||||
}
|
||||
|
||||
private void UndoExecuted() {
|
||||
|
|
@ -191,7 +197,7 @@ namespace HavenSoft.HexManiac.Core.ViewModels {
|
|||
if (previouslyHadDataChanged != HasDataChange) NotifyPropertyChanged(nameof(HasDataChange));
|
||||
}
|
||||
|
||||
private void VerifyRevertNotInProgress([CallerMemberName]string caller = null) {
|
||||
private void VerifyRevertNotInProgress([CallerMemberName] string caller = null) {
|
||||
if (!revertInProgress) return;
|
||||
throw new InvalidOperationException($"Cannot execute member {caller} while a revert is in progress.");
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user