mirror of
https://github.com/anyproto/any-sync.git
synced 2025-06-07 21:47:02 +09:00
Merge pull request #462 from anyproto/GO-5741-optimize-ldiff
GO-5741 optimize ldiff compare
This commit is contained in:
commit
31d1deb0c8
1 changed files with 15 additions and 7 deletions
|
@ -381,17 +381,24 @@ func (d *diff) compareResults(dctx *diffCtx, r Range, myRes, otherRes RangeResul
|
|||
}
|
||||
|
||||
func (d *diff) compareElementsEqual(dctx *diffCtx, my, other []Element) {
|
||||
find := func(list []Element, targetEl Element) (has, eq bool) {
|
||||
for _, el := range list {
|
||||
if el.Id == targetEl.Id {
|
||||
return true, el.Head == targetEl.Head
|
||||
}
|
||||
find := func(list map[string]string, targetEl Element) (has, eq bool) {
|
||||
if head, ok := list[targetEl.Id]; ok {
|
||||
return true, head == targetEl.Head
|
||||
}
|
||||
return false, false
|
||||
}
|
||||
|
||||
toMap := func(els []Element) map[string]string {
|
||||
result := make(map[string]string, len(els))
|
||||
for _, el := range els {
|
||||
result[el.Id] = el.Head
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
otherMap := toMap(other)
|
||||
for _, el := range my {
|
||||
has, eq := find(other, el)
|
||||
has, eq := find(otherMap, el)
|
||||
if !has {
|
||||
dctx.removedIds = append(dctx.removedIds, el.Id)
|
||||
continue
|
||||
|
@ -402,8 +409,9 @@ func (d *diff) compareElementsEqual(dctx *diffCtx, my, other []Element) {
|
|||
}
|
||||
}
|
||||
|
||||
myMap := toMap(my)
|
||||
for _, el := range other {
|
||||
if has, _ := find(my, el); !has {
|
||||
if has, _ := find(myMap, el); !has {
|
||||
dctx.newIds = append(dctx.newIds, el.Id)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue