@@ -52,11 +52,9 @@ type dumpState struct {
5252 w io.Writer
5353 depth int
5454 pointers map [uintptr ]int
55- allPointers map [uintptr ]uintptr
5655 ignoreNextType bool
5756 ignoreNextIndent bool
5857 cs * ConfigState
59- nextOrdinal uintptr
6058}
6159
6260// indent performs indentation according to the depth level and cs.Indent
@@ -79,50 +77,6 @@ func (d *dumpState) unpackValue(v reflect.Value) reflect.Value {
7977 return v
8078}
8179
82- func (d * dumpState ) isPointerSeen (addr uintptr ) (seen bool , ordinal uintptr ) {
83- ordinal = uintptr (addr )
84-
85- if d .allPointers == nil {
86- return false , ordinal
87- }
88-
89- // d.cs.NoDuplicates || d.cs.UseOrdinals
90- duplicateFound := false
91- if ord , ok := d .allPointers [addr ]; ok {
92- if d .cs .UseOrdinals {
93- ordinal = ord
94- }
95- if d .cs .NoDuplicates {
96- duplicateFound = true
97- }
98- } else {
99- if d .cs .UseOrdinals {
100- d .nextOrdinal ++
101- ordinal = d .nextOrdinal
102- }
103- d .allPointers [addr ] = ordinal
104- }
105-
106- return duplicateFound , ordinal
107- }
108-
109- func (d * dumpState ) printPtrOrOrdinal (addr uintptr ) {
110- if d .cs .UseOrdinals {
111- printOrdinal (d .w , addr )
112- } else {
113- printHexPtr (d .w , addr )
114- }
115- }
116-
117- func (d * dumpState ) printPtr (addr uintptr ) {
118- if d .cs .UseOrdinals {
119- _ , addr := d .isPointerSeen (addr )
120- printOrdinal (d .w , addr )
121- } else {
122- printHexPtr (d .w , addr )
123- }
124- }
125-
12680// dumpPtr handles formatting of pointers by indirecting them as necessary.
12781func (d * dumpState ) dumpPtr (v reflect.Value ) {
12882 // Remove pointers at or below the current depth from map used to detect
@@ -141,7 +95,6 @@ func (d *dumpState) dumpPtr(v reflect.Value) {
14195 // references.
14296 nilFound := false
14397 cycleFound := false
144- duplicateFound := false
14598 indirects := 0
14699 ve := v
147100 for ve .Kind () == reflect .Ptr {
@@ -151,21 +104,12 @@ func (d *dumpState) dumpPtr(v reflect.Value) {
151104 }
152105 indirects ++
153106 addr := ve .Pointer ()
154-
107+ pointerChain = append ( pointerChain , addr )
155108 if pd , ok := d .pointers [addr ]; ok && pd < d .depth {
156109 cycleFound = true
157- }
158-
159- dup , ordinal := d .isPointerSeen (addr )
160-
161- pointerChain = append (pointerChain , ordinal )
162-
163- if cycleFound || dup {
164110 indirects --
165- duplicateFound = true
166111 break
167112 }
168-
169113 d .pointers [addr ] = d .depth
170114
171115 ve = ve .Elem ()
@@ -191,7 +135,7 @@ func (d *dumpState) dumpPtr(v reflect.Value) {
191135 if i > 0 {
192136 d .w .Write (pointerChainBytes )
193137 }
194- d . printPtrOrOrdinal ( addr )
138+ printHexPtr ( d . w , addr )
195139 }
196140 d .w .Write (closeParenBytes )
197141 }
@@ -205,9 +149,6 @@ func (d *dumpState) dumpPtr(v reflect.Value) {
205149 case cycleFound :
206150 d .w .Write (circularBytes )
207151
208- case duplicateFound :
209- d .w .Write (duplicateBytes )
210-
211152 default :
212153 d .ignoreNextType = true
213154 d .dump (ve )
@@ -441,7 +382,6 @@ func (d *dumpState) dump(v reflect.Value) {
441382 d .indent ()
442383 d .w .Write (maxNewlineBytes )
443384 } else {
444- v = unsafeReflectValue (v )
445385 numEntries := v .Len ()
446386 keys := v .MapKeys ()
447387 if d .cs .SortKeys {
@@ -491,10 +431,10 @@ func (d *dumpState) dump(v reflect.Value) {
491431 d .w .Write (closeBraceBytes )
492432
493433 case reflect .Uintptr :
494- d . printPtr ( uintptr (v .Uint ()))
434+ printHexPtr ( d . w , uintptr (v .Uint ()))
495435
496436 case reflect .UnsafePointer , reflect .Chan , reflect .Func :
497- d . printPtr ( v .Pointer ())
437+ printHexPtr ( d . w , v .Pointer ())
498438
499439 // There were not any other types at the time this code was written, but
500440 // fall back to letting the default fmt package handle it in case any new
@@ -522,9 +462,6 @@ func fdump(cs *ConfigState, w io.Writer, a ...interface{}) {
522462
523463 d := dumpState {w : w , cs : cs }
524464 d .pointers = make (map [uintptr ]int )
525- if cs .NoDuplicates || cs .UseOrdinals {
526- d .allPointers = make (map [uintptr ]uintptr )
527- }
528465 d .dump (reflect .ValueOf (arg ))
529466 d .w .Write (newlineBytes )
530467 }
0 commit comments