Skip to content

Commit

Permalink
slice: use comparisons without subtraction
Browse files Browse the repository at this point in the history
  • Loading branch information
creachadair committed Nov 9, 2024
1 parent 4267dc9 commit 244c819
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions slice/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func editScriptFunc[T any, Slice ~[]T](eq func(a, b T) bool, lhs, rhs Slice) []E

// If we have both deletions and copies, combine them in a single replace
// instruction.
if lend-lpos > 0 && rend-rpos > 0 {
if lend > lpos && rend > rpos {
out = append(out, Edit[T]{Op: OpReplace, X: lhs[lpos:lend], Y: rhs[rpos:rend]})
rpos = rend
} else if lend > lpos {
Expand Down Expand Up @@ -197,7 +197,7 @@ func editScriptFunc[T any, Slice ~[]T](eq func(a, b T) bool, lhs, rhs Slice) []E

// If we have both deletions and copies, combine them in a single replace
// instruction.
if len(lhs)-lpos > 0 && len(rhs)-rpos > 0 {
if len(lhs) > lpos && len(rhs) > rpos {
out = append(out, Edit[T]{Op: OpReplace, X: lhs[lpos:], Y: rhs[rpos:]})
rpos = len(rhs)
} else if len(lhs) > lpos {
Expand Down

0 comments on commit 244c819

Please sign in to comment.