Skip to content

Commit 8926f29

Browse files
committed
Cleanup
1 parent 6f96beb commit 8926f29

File tree

2 files changed

+13
-23
lines changed

2 files changed

+13
-23
lines changed

internal/hscan/hscan.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ var (
3434
reflect.Interface: decodeUnsupported,
3535
reflect.Map: decodeUnsupported,
3636
reflect.Ptr: decodeUnsupported,
37-
reflect.Slice: decodeStringSlice,
37+
reflect.Slice: decodeSlice,
3838
reflect.String: decodeString,
3939
reflect.Struct: decodeUnsupported,
4040
reflect.UnsafePointer: decodeUnsupported,
@@ -69,12 +69,7 @@ func Scan(vals []interface{}, dest interface{}) error {
6969
// iterating through the fields of a struct type every time values are
7070
// scanned into it.
7171
typ := v.Type()
72-
fMap, ok := structSpecs.get(typ)
73-
74-
if !ok {
75-
fMap = makeStructSpecs(v, "redis")
76-
structSpecs.set(typ, fMap)
77-
}
72+
fMap := structSpecs.get(typ)
7873

7974
// Iterate through the (key, value) sequence.
8075
for i := 0; i < len(vals); i += 2 {
@@ -143,14 +138,14 @@ func decodeString(f reflect.Value, s string) error {
143138
return nil
144139
}
145140

146-
func decodeStringSlice(f reflect.Value, s string) error {
141+
func decodeSlice(f reflect.Value, s string) error {
147142
// []byte slice ([]uint8).
148143
if f.Type().Elem().Kind() == reflect.Uint8 {
149144
f.SetBytes([]byte(s))
150145
}
151146
return nil
152147
}
153148

154-
func decodeUnsupported(f reflect.Value, s string) error {
155-
return fmt.Errorf("redis.Scan(unsupported type %v)", f)
149+
func decodeUnsupported(v reflect.Value, s string) error {
150+
return fmt.Errorf("redis.Scan(unsupported %s)", v.Type())
156151
}

internal/hscan/structmap.go

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,17 @@ type structMap struct {
2424
}
2525

2626
func newStructMap() *structMap {
27-
return &structMap{
28-
m: sync.Map{},
29-
}
27+
return new(structMap)
3028
}
3129

32-
func (s *structMap) get(t reflect.Type) (*structFields, bool) {
33-
m, ok := s.m.Load(t)
34-
if !ok {
35-
return nil, ok
30+
func (s *structMap) get(t reflect.Type) *structFields {
31+
if v, ok := s.m.Load(t); ok {
32+
return m.(*structFields), ok
3633
}
3734

38-
return m.(*structFields), true
39-
}
40-
41-
func (s *structMap) set(t reflect.Type, sf *structFields) {
42-
s.m.Store(t, sf)
35+
fMap := getStructFields(v, "redis")
36+
s.m.Store(t, fMap)
37+
return fmap, true
4338
}
4439

4540
func newStructFields() *structFields {
@@ -57,7 +52,7 @@ func (s *structFields) get(tag string) (*structField, bool) {
5752
return f, ok
5853
}
5954

60-
func makeStructSpecs(ob reflect.Value, fieldTag string) *structFields {
55+
func getStructFields(ob reflect.Value, fieldTag string) *structFields {
6156
var (
6257
num = ob.NumField()
6358
out = newStructFields()

0 commit comments

Comments
 (0)