Skip to content

Commit c4a4925

Browse files
committed
unsafe.Pointer -> uintptr: Wether the underlying value is still accessible or has been garbage collected is irrelevant to us
1 parent 998cbd0 commit c4a4925

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

diff/cyclic_detection.go

+10-11
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package diff
33
import (
44
"errors"
55
"reflect"
6-
"unsafe"
76
)
87

98
// ErrCyclic is returned when one of the compared values contain circular references
@@ -12,41 +11,41 @@ var ErrCyclic = errors.New("circular references not supported")
1211
// visited is used to detect cyclic structures.
1312
// It is not safe for concurent use.
1413
type visited struct {
15-
lhs []unsafe.Pointer
16-
rhs []unsafe.Pointer
14+
lhs []uintptr
15+
rhs []uintptr
1716
}
1817

1918
// add will try to add the value's pointers to the list. It will return an error
2019
// if the value is already in the list.
2120
// visited.remove should be called whether an error occured or not.
2221
func (v *visited) add(lhs, rhs reflect.Value) error {
2322
if canAddr(lhs) && !isEmptyMapOrSlice(lhs) {
24-
if inPointers(v.lhs, unsafe.Pointer(lhs.Pointer())) {
23+
if inPointers(v.lhs, lhs.Pointer()) {
2524
return ErrCyclic
2625
}
27-
v.lhs = append(v.lhs, unsafe.Pointer(lhs.Pointer()))
26+
v.lhs = append(v.lhs, lhs.Pointer())
2827
}
2928
if canAddr(rhs) && !isEmptyMapOrSlice(rhs) {
30-
if inPointers(v.rhs, unsafe.Pointer(rhs.Pointer())) {
29+
if inPointers(v.rhs, rhs.Pointer()) {
3130
return ErrCyclic
3231
}
33-
v.rhs = append(v.rhs, unsafe.Pointer(rhs.Pointer()))
32+
v.rhs = append(v.rhs, rhs.Pointer())
3433
}
3534

3635
return nil
3736
}
3837

3938
func (v *visited) remove(lhs, rhs reflect.Value) {
40-
if canAddr(lhs) && isLastPointer(v.lhs, unsafe.Pointer(lhs.Pointer())) {
39+
if canAddr(lhs) && isLastPointer(v.lhs, lhs.Pointer()) {
4140
v.lhs = v.lhs[:len(v.lhs)-1]
4241
}
4342

44-
if canAddr(rhs) && isLastPointer(v.rhs, unsafe.Pointer(rhs.Pointer())) {
43+
if canAddr(rhs) && isLastPointer(v.rhs, rhs.Pointer()) {
4544
v.rhs = v.rhs[:len(v.rhs)-1]
4645
}
4746
}
4847

49-
func isLastPointer(pointers []unsafe.Pointer, val unsafe.Pointer) bool {
48+
func isLastPointer(pointers []uintptr, val uintptr) bool {
5049
if len(pointers) == 0 {
5150
return false
5251
}
@@ -59,7 +58,7 @@ func isEmptyMapOrSlice(v reflect.Value) bool {
5958
return (v.Kind() == reflect.Slice || v.Kind() == reflect.Map) && v.Len() == 0
6059
}
6160

62-
func inPointers(pointers []unsafe.Pointer, val unsafe.Pointer) bool {
61+
func inPointers(pointers []uintptr, val uintptr) bool {
6362
for _, lhs := range pointers {
6463
if lhs == val {
6564
return true

0 commit comments

Comments
 (0)