Skip to content

Commit 32aebcd

Browse files
committed
rename from SetCache to Bind
1 parent 247a6a6 commit 32aebcd

File tree

7 files changed

+19
-16
lines changed

7 files changed

+19
-16
lines changed

checker/checker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ func (v *Checker) callNode(node *ast.CallNode) Nature {
636636
// with new correct function return type.
637637
if typ := node.Type(); typ != nil && typ != anyType {
638638
nt := node.Nature()
639-
nt.SetCache(&v.config.NtCache) // AST doesn't cache nature info
639+
nt.Bind(&v.config.NtCache) // AST doesn't cache nature info
640640
return nt
641641
}
642642

checker/info.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func FieldIndex(c *Cache, env Nature, node ast.Node) (bool, []int, string) {
1616
}
1717
case *ast.MemberNode:
1818
base := n.Node.Nature()
19-
base.SetCache(c) // AST doesn't cache nature info
19+
base.Bind(c) // AST doesn't cache nature info
2020
base = base.Deref()
2121
if base.Kind == reflect.Struct {
2222
if prop, ok := n.Property.(*ast.StringNode); ok {

checker/nature/nature.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ func (c *Cache) getStruct(t reflect.Type) Nature {
137137
},
138138
}
139139
if c != nil {
140-
nt.SetCache(c)
140+
nt.Bind(c)
141141
}
142142
return nt
143143
}
@@ -187,27 +187,30 @@ func ArrayFromType(c *Cache, t reflect.Type) Nature {
187187
return nt
188188
}
189189

190-
func (n *Nature) SetCache(c *Cache) {
190+
func (n *Nature) Bind(c *Cache) {
191+
if n.cache == c {
192+
return
193+
}
191194
n.cache = c
192195
if n.Kind == reflect.Struct {
193196
if c.structs == nil {
194-
n.structData.setCache(c)
197+
n.structData.bind(c)
195198
c.structs = map[reflect.Type]Nature{
196199
n.Type: *n,
197200
}
198201
} else if nt, ok := c.structs[n.Type]; ok {
199202
// invalidate local, use shared from cache
200203
n.Optional.structData = nt.Optional.structData
201204
} else {
202-
n.structData.setCache(c)
205+
n.structData.bind(c)
203206
c.structs[n.Type] = *n
204207
}
205208
}
206209
hasMethodset := n.Optional != nil && n.Optional.methodset != nil
207210
if c.methods != nil || hasMethodset {
208211
if c.methods == nil {
209212
// Cache is new and the type already gathered some methods
210-
n.Optional.methodset.setCache(c)
213+
n.Optional.methodset.bind(c)
211214
c.methods = map[reflect.Type]*methodset{
212215
n.Type: n.Optional.methodset,
213216
}
@@ -219,7 +222,7 @@ func (n *Nature) SetCache(c *Cache) {
219222
n.Optional.methodset = s
220223
} else if hasMethodset {
221224
// Cache miss and the type already gathered some methods
222-
n.Optional.methodset.setCache(c)
225+
n.Optional.methodset.bind(c)
223226
c.methods[n.Type] = n.Optional.methodset
224227
}
225228
}

checker/nature/utils.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ type structField struct {
3232
Index []int
3333
}
3434

35-
func (s *structData) setCache(c *Cache) {
35+
func (s *structData) bind(c *Cache) {
3636
s.cache = c
3737
for _, sf := range s.fields {
38-
sf.SetCache(c)
38+
sf.Bind(c)
3939
}
4040
}
4141

@@ -204,10 +204,10 @@ type method struct {
204204
nature Nature
205205
}
206206

207-
func (s *methodset) setCache(c *Cache) {
207+
func (s *methodset) bind(c *Cache) {
208208
s.cache = c
209209
for _, m := range s.methods {
210-
m.nature.SetCache(c)
210+
m.nature.Bind(c)
211211
}
212212
}
213213

compiler/compiler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,7 @@ func (c *compiler) BuiltinNode(node *ast.BuiltinNode) {
10891089
c.compile(arg)
10901090
argType := arg.Type()
10911091
argNature := arg.Nature()
1092-
argNature.SetCache(c.ntCache) // AST doesn't cache nature info
1092+
argNature.Bind(c.ntCache) // AST doesn't cache nature info
10931093
if argType.Kind() == reflect.Ptr || argNature.IsUnknown() {
10941094
if f.Deref == nil {
10951095
// By default, builtins expect arguments to be dereferenced.

conf/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func CreateNew() *Config {
5050
for _, f := range builtin.Builtins {
5151
c.Builtins[f.Name] = f
5252
}
53-
c.Env.SetCache(&c.NtCache)
53+
c.Env.Bind(&c.NtCache)
5454
return c
5555
}
5656

conf/env.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func EnvWithCache(c *Cache, env any) Nature {
2626
switch env := env.(type) {
2727
case types.Map:
2828
nt := env.Nature()
29-
nt.SetCache(c)
29+
nt.Bind(c)
3030
return nt
3131
}
3232

@@ -58,7 +58,7 @@ func EnvWithCache(c *Cache, env any) Nature {
5858
switch face := face.(type) {
5959
case types.Map:
6060
nt := face.Nature()
61-
nt.SetCache(c)
61+
nt.Bind(c)
6262
n.Fields[key.String()] = nt
6363

6464
default:

0 commit comments

Comments
 (0)