diff --git a/internal/buffer/buffer.go b/internal/buffer/buffer.go index c1bf6f10..1d899663 100644 --- a/internal/buffer/buffer.go +++ b/internal/buffer/buffer.go @@ -64,10 +64,6 @@ var ( // BTStdout is a buffer that only writes to stdout // when closed BTStdout = BufType{6, false, true, true} - - // ErrFileTooLarge is returned when the file is too large to hash - // (fastdirty is automatically enabled) - ErrFileTooLarge = errors.New("File is too large to hash") ) // SharedBuffer is a struct containing info that is shared among buffers @@ -649,32 +645,23 @@ func (b *Buffer) Size() int { } // calcHash calculates md5 hash of all lines in the buffer -func calcHash(b *Buffer, out *[md5.Size]byte) error { +func calcHash(b *Buffer, out *[md5.Size]byte) { h := md5.New() - size := 0 if len(b.lines) > 0 { - n, _ := h.Write(b.lines[0].data) - size += n + h.Write(b.lines[0].data) for _, l := range b.lines[1:] { if b.Endings == FFDos { - n, _ = h.Write([]byte{'\r', '\n'}) + h.Write([]byte{'\r', '\n'}) } else { - n, _ = h.Write([]byte{'\n'}) + h.Write([]byte{'\n'}) } - size += n - n, _ = h.Write(l.data) - size += n + h.Write(l.data) } } - if size > LargeFileThreshold { - return ErrFileTooLarge - } - h.Sum((*out)[:0]) - return nil } func parseDefFromFile(f config.RuntimeFile, header *highlight.Header) *highlight.Def { diff --git a/internal/buffer/settings.go b/internal/buffer/settings.go index e934da2f..9e76697c 100644 --- a/internal/buffer/settings.go +++ b/internal/buffer/settings.go @@ -12,15 +12,13 @@ func (b *Buffer) SetOptionNative(option string, nativeValue interface{}) error { if option == "fastdirty" { if !nativeValue.(bool) { - if !b.isModified { - e := calcHash(b, &b.origHash) - if e == ErrFileTooLarge { - b.Settings["fastdirty"] = true - } + if b.Size() > LargeFileThreshold { + b.Settings["fastdirty"] = true } else { - b.origHash = [md5.Size]byte{} - if b.Size() > LargeFileThreshold { - b.Settings["fastdirty"] = true + if !b.isModified { + calcHash(b, &b.origHash) + } else { + b.origHash = [md5.Size]byte{} } } }