Skip to content

Commit 76ee775

Browse files
committed
improving 'visited' methods names
1 parent c4a4925 commit 76ee775

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

diff/cyclic_detection.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ type visited struct {
1515
rhs []uintptr
1616
}
1717

18-
// add will try to add the value's pointers to the list. It will return an error
18+
// push will try to add the value's pointers to the list. It will return an error
1919
// if the value is already in the list.
2020
// visited.remove should be called whether an error occured or not.
21-
func (v *visited) add(lhs, rhs reflect.Value) error {
21+
func (v *visited) push(lhs, rhs reflect.Value) error {
2222
if canAddr(lhs) && !isEmptyMapOrSlice(lhs) {
2323
if inPointers(v.lhs, lhs.Pointer()) {
2424
return ErrCyclic
@@ -35,22 +35,22 @@ func (v *visited) add(lhs, rhs reflect.Value) error {
3535
return nil
3636
}
3737

38-
func (v *visited) remove(lhs, rhs reflect.Value) {
39-
if canAddr(lhs) && isLastPointer(v.lhs, lhs.Pointer()) {
38+
func (v *visited) pop(lhs, rhs reflect.Value) {
39+
if canAddr(lhs) && lastElementEquals(v.lhs, lhs.Pointer()) {
4040
v.lhs = v.lhs[:len(v.lhs)-1]
4141
}
4242

43-
if canAddr(rhs) && isLastPointer(v.rhs, rhs.Pointer()) {
43+
if canAddr(rhs) && lastElementEquals(v.rhs, rhs.Pointer()) {
4444
v.rhs = v.rhs[:len(v.rhs)-1]
4545
}
4646
}
4747

48-
func isLastPointer(pointers []uintptr, val uintptr) bool {
49-
if len(pointers) == 0 {
48+
func lastElementEquals(uu []uintptr, val uintptr) bool {
49+
if len(uu) == 0 {
5050
return false
5151
}
5252

53-
return pointers[len(pointers)-1] == val
53+
return uu[len(uu)-1] == val
5454
}
5555

5656
func isEmptyMapOrSlice(v reflect.Value) bool {

diff/diff.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ func diff(c config, lhs, rhs interface{}, visited *visited) (Differ, error) {
5050
return d, nil
5151
}
5252

53-
err := visited.add(lhsVal, rhsVal)
54-
defer visited.remove(lhsVal, rhsVal)
53+
err := visited.push(lhsVal, rhsVal)
54+
defer visited.pop(lhsVal, rhsVal)
5555
if err != nil {
5656
return types{lhs, rhs}, ErrCyclic
5757
}

0 commit comments

Comments
 (0)