Skip to content

Commit dc62dd9

Browse files
authored
autosave: don't save unmodified buffer (zyedidia#3356)
Saving a buffer every time without even checking if it was modified (i.e. even when the user is not editing the buffer) is wasteful, especially if the autosave period is set to a short value.
1 parent ced6d94 commit dc62dd9

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

internal/buffer/save.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ func (b *Buffer) Save() error {
9595

9696
// AutoSave saves the buffer to its default path
9797
func (b *Buffer) AutoSave() error {
98+
// Doing full b.Modified() check every time would be costly, due to the hash
99+
// calculation. So use just isModified even if fastdirty is not set.
100+
if !b.isModified {
101+
return nil
102+
}
98103
return b.saveToFile(b.Path, false, true)
99104
}
100105

0 commit comments

Comments
 (0)