"crypto/md5"
"encoding/json"
"errors"
+ "io"
"io/ioutil"
"os"
"reflect"
"strconv"
"strings"
+ "sync"
"github.com/flynn/json5"
"github.com/zyedidia/glob"
"eofnewline": false,
"fastdirty": true,
"fileformat": "unix",
+ "hidehelp": false,
"ignorecase": false,
"indentchar": " ",
"infobar": true,
"keepautoindent": false,
"keymenu": false,
"matchbrace": false,
+ "matchbraceleft": false,
"mouse": true,
"pluginchannels": []string{"https://raw.githubusercontent.com/micro-editor/plugin-channel/master/channel.json"},
"pluginrepos": []string{},
"fastdirty": true,
"fileformat": "unix",
"filetype": "Unknown",
+ "hidehelp": false,
"ignorecase": false,
"indentchar": " ",
"keepautoindent": false,
"matchbrace": false,
+ "matchbraceleft": false,
"rmtrailingws": false,
"ruler": true,
"savecursor": false,
if option == "fastdirty" {
// If it is being turned off, we have to hash every open buffer
- var empty [16]byte
+ var empty [md5.Size]byte
+ var wg sync.WaitGroup
+
for _, tab := range tabs {
for _, v := range tab.Views {
if !nativeValue.(bool) {
if v.Buf.origHash == empty {
- data, err := ioutil.ReadFile(v.Buf.AbsPath)
- if err != nil {
- data = []byte{}
- }
- v.Buf.origHash = md5.Sum(data)
+ wg.Add(1)
+
+ go func(b *Buffer) { // calculate md5 hash of the file
+ defer wg.Done()
+
+ if file, e := os.Open(b.AbsPath); e == nil {
+ defer file.Close()
+
+ h := md5.New()
+
+ if _, e = io.Copy(h, file); e == nil {
+ h.Sum(b.origHash[:0])
+ }
+ }
+ }(v.Buf)
}
} else {
v.Buf.IsModified = v.Buf.Modified()
}
}
}
+
+ wg.Wait()
}
buf.Settings[option] = nativeValue