use defer rather than call unlock at end of function

This commit is contained in:
Jesse Duffield 2019-05-18 12:49:10 +10:00
parent 3cd3a41702
commit 9f871b6b9d

View File

@ -228,6 +228,7 @@ func (v *View) Origin() (x, y int) {
func (v *View) Write(p []byte) (n int, err error) {
v.tainted = true
v.writeMutex.Lock()
defer v.writeMutex.Unlock()
for _, ch := range bytes.Runes(p) {
switch ch {
@ -254,7 +255,7 @@ func (v *View) Write(p []byte) (n int, err error) {
}
}
}
v.writeMutex.Unlock()
return len(p), nil
}