mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-08 14:18:26 +02:00
Micro optimisation
This commit is contained in:
@@ -287,10 +287,13 @@ func (dc *DiskCache) add(key string, items map[string][]byte) (err error) {
|
|||||||
for x, data := range items {
|
for x, data := range items {
|
||||||
p := filepath.Join(base, x)
|
p := filepath.Join(base, x)
|
||||||
var before int64
|
var before int64
|
||||||
|
exists := false
|
||||||
if s, err := os.Stat(p); err == nil {
|
if s, err := os.Stat(p); err == nil {
|
||||||
before = s.Size()
|
before = s.Size()
|
||||||
|
exists = true
|
||||||
}
|
}
|
||||||
if len(data) == 0 {
|
if len(data) == 0 {
|
||||||
|
if exists {
|
||||||
if err = os.Remove(p); err != nil {
|
if err = os.Remove(p); err != nil {
|
||||||
if !os.IsNotExist(err) {
|
if !os.IsNotExist(err) {
|
||||||
return
|
return
|
||||||
@@ -298,10 +301,13 @@ func (dc *DiskCache) add(key string, items map[string][]byte) (err error) {
|
|||||||
err = nil
|
err = nil
|
||||||
}
|
}
|
||||||
changed -= before
|
changed -= before
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// unlink the file so that writing to it does not change a
|
// unlink the file so that writing to it does not change a
|
||||||
// previously linked copy created by get()
|
// previously linked copy created by get()
|
||||||
|
if exists {
|
||||||
_ = os.Remove(p)
|
_ = os.Remove(p)
|
||||||
|
}
|
||||||
if err = os.WriteFile(p, data, 0o700); err != nil {
|
if err = os.WriteFile(p, data, 0o700); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user