Skip to content

Commit

Permalink
autosave: don't save unmodified buffer (#3356)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dmaluka authored Jun 17, 2024
1 parent ced6d94 commit dc62dd9
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/buffer/save.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ func (b *Buffer) Save() error {

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

Expand Down

0 comments on commit dc62dd9

Please sign in to comment.