@@ -140,6 +140,26 @@ func (b *SharedBuffer) remove(start, end Loc) []byte {
140140 return b .LineArray .remove (start , end )
141141}
142142
143+ // calcHash calculates md5 hash of all lines in the buffer
144+ func (b * SharedBuffer ) calcHash (out * [md5 .Size ]byte ) {
145+ h := md5 .New ()
146+
147+ if len (b .lines ) > 0 {
148+ h .Write (b .lines [0 ].data )
149+
150+ for _ , l := range b .lines [1 :] {
151+ if b .Endings == FFDos {
152+ h .Write ([]byte {'\r' , '\n' })
153+ } else {
154+ h .Write ([]byte {'\n' })
155+ }
156+ h .Write (l .data )
157+ }
158+ }
159+
160+ h .Sum ((* out )[:0 ])
161+ }
162+
143163// MarkModified marks the buffer as modified for this frame
144164// and performs rehighlighting if syntax highlighting is enabled
145165func (b * SharedBuffer ) MarkModified (start , end int ) {
@@ -416,7 +436,7 @@ func NewBuffer(r io.Reader, size int64, path string, startcursor Loc, btype BufT
416436 } else if ! hasBackup {
417437 // since applying a backup does not save the applied backup to disk, we should
418438 // not calculate the original hash based on the backup data
419- calcHash (b , & b .origHash )
439+ b . calcHash (& b .origHash )
420440 }
421441 }
422442
@@ -558,7 +578,7 @@ func (b *Buffer) ReOpen() error {
558578 if len (data ) > LargeFileThreshold {
559579 b .Settings ["fastdirty" ] = true
560580 } else {
561- calcHash (b , & b .origHash )
581+ b . calcHash (& b .origHash )
562582 }
563583 }
564584 b .isModified = false
@@ -643,7 +663,7 @@ func (b *Buffer) Modified() bool {
643663
644664 var buff [md5 .Size ]byte
645665
646- calcHash (b , & buff )
666+ b . calcHash (& buff )
647667 return buff != b .origHash
648668}
649669
@@ -663,26 +683,6 @@ func (b *Buffer) Size() int {
663683 return nb
664684}
665685
666- // calcHash calculates md5 hash of all lines in the buffer
667- func calcHash (b * Buffer , out * [md5 .Size ]byte ) {
668- h := md5 .New ()
669-
670- if len (b .lines ) > 0 {
671- h .Write (b .lines [0 ].data )
672-
673- for _ , l := range b .lines [1 :] {
674- if b .Endings == FFDos {
675- h .Write ([]byte {'\r' , '\n' })
676- } else {
677- h .Write ([]byte {'\n' })
678- }
679- h .Write (l .data )
680- }
681- }
682-
683- h .Sum ((* out )[:0 ])
684- }
685-
686686func parseDefFromFile (f config.RuntimeFile , header * highlight.Header ) * highlight.Def {
687687 data , err := f .Data ()
688688 if err != nil {
0 commit comments