mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-16 05:47:06 +09:00
Optimization for IsDirty()
This commit is contained in:
@@ -19,7 +19,8 @@ type Buffer struct {
|
|||||||
name string
|
name string
|
||||||
|
|
||||||
// This is the text stored every time the buffer is saved to check if the buffer is modified
|
// This is the text stored every time the buffer is saved to check if the buffer is modified
|
||||||
savedText string
|
savedText string
|
||||||
|
netInsertions int
|
||||||
|
|
||||||
// Provide efficient and easy access to text and lines so the rope String does not
|
// Provide efficient and easy access to text and lines so the rope String does not
|
||||||
// need to be constantly recalculated
|
// need to be constantly recalculated
|
||||||
@@ -84,11 +85,15 @@ func (b *Buffer) SaveAs(filename string) error {
|
|||||||
|
|
||||||
// IsDirty returns whether or not the buffer has been modified compared to the one on disk
|
// IsDirty returns whether or not the buffer has been modified compared to the one on disk
|
||||||
func (b *Buffer) IsDirty() bool {
|
func (b *Buffer) IsDirty() bool {
|
||||||
return b.savedText != b.text
|
if b.netInsertions == 0 {
|
||||||
|
return b.savedText != b.text
|
||||||
|
}
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert a string into the rope
|
// Insert a string into the rope
|
||||||
func (b *Buffer) Insert(idx int, value string) {
|
func (b *Buffer) Insert(idx int, value string) {
|
||||||
|
b.netInsertions += len(value)
|
||||||
b.r = b.r.Insert(idx, value)
|
b.r = b.r.Insert(idx, value)
|
||||||
b.Update()
|
b.Update()
|
||||||
}
|
}
|
||||||
@@ -96,6 +101,7 @@ func (b *Buffer) Insert(idx int, value string) {
|
|||||||
// Remove a slice of the rope from start to end (exclusive)
|
// Remove a slice of the rope from start to end (exclusive)
|
||||||
// Returns the string that was removed
|
// Returns the string that was removed
|
||||||
func (b *Buffer) Remove(start, end int) string {
|
func (b *Buffer) Remove(start, end int) string {
|
||||||
|
b.netInsertions -= end - start
|
||||||
if start < 0 {
|
if start < 0 {
|
||||||
start = 0
|
start = 0
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user