Skip to content

Commit

Permalink
Use SetIterKey/SetIterValue
Browse files Browse the repository at this point in the history
Compared to previous commit:

```
       │ stash.bench │        fix-setiterval.bench        │
       │   sec/op    │   sec/op     vs base               │
Map-10   3.159µ ± 1%   2.609µ ± 1%  -17.44% (p=0.002 n=6)

       │ stash.bench │       fix-setiterval.bench        │
       │    B/op     │    B/op     vs base               │
Map-10   1360.0 ± 0%   752.0 ± 0%  -44.71% (p=0.002 n=6)

       │ stash.bench │       fix-setiterval.bench        │
       │  allocs/op  │ allocs/op   vs base               │
Map-10   128.00 ± 0%   90.00 ± 0%  -29.69% (p=0.002 n=6)
```

Compared to 1dee3c3:

```
       │ 1dee3c3.bench │        fix-setiterval.bench        │
       │                     sec/op                     │   sec/op     vs base               │
Map-10                                      3.608µ ± 1%   2.537µ ± 1%  -29.68% (p=0.002 n=6)

       │ 1dee3c3.bench │       fix-setiterval.bench        │
       │                      B/op                      │    B/op     vs base               │
Map-10                                      1888.0 ± 0%   752.0 ± 0%  -60.17% (p=0.002 n=6)

       │ 1dee3c3.bench │       fix-setiterval.bench        │
       │                   allocs/op                    │ allocs/op   vs base               │
Map-10                                      130.00 ± 0%   90.00 ± 0%  -30.77% (p=0.002 n=6)
````
  • Loading branch information
bep committed Jan 13, 2025
1 parent 669eafd commit 18d2e7b
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions hashstructure.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,12 +220,16 @@ func (w *walker) visit(v reflect.Value, opts *visitOpts) (uint64, error) {
// and value hashes. This makes it deterministic despite ordering.
var h uint64

k := reflect.New(v.Type().Key()).Elem()
vv := reflect.New(v.Type().Elem()).Elem()

iter := v.MapRange()

for iter.Next() {
k := iter.Key()
v := iter.Value()
k.SetIterKey(iter)
vv.SetIterValue(iter)
if includeMap != nil {
incl, err := includeMap.HashIncludeMap(field, k.Interface(), v.Interface())
incl, err := includeMap.HashIncludeMap(field, k.Interface(), vv.Interface())
if err != nil {
return 0, err
}
Expand All @@ -238,7 +242,7 @@ func (w *walker) visit(v reflect.Value, opts *visitOpts) (uint64, error) {
if err != nil {
return 0, err
}
vh, err := w.visit(v, nil)
vh, err := w.visit(vv, nil)
if err != nil {
return 0, err
}
Expand Down

2 comments on commit 18d2e7b

@jcbhmr
Copy link

@jcbhmr jcbhmr commented on 18d2e7b Feb 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @bep! I don't know where to leave a comment on this repository since Issues is turned off. That's actually what this comment is about. Would you be willing to enable Issues on https://github.com/gohugoio/hashstructure (this repository)?

@bep
Copy link
Member Author

@bep bep commented on 18d2e7b Feb 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jcbhmr Done.

Please sign in to comment.