MCPcopy Index your code
hub / github.com/Shopify/go-lua / tryPut

Method tryPut

tables.go:148–173  ·  view source on GitHub ↗

OPT: tryPut is an optimized variant of the at/put pair used by setTableAt to avoid hashing the key twice.

(l *State, k, v value)

Source from the content-addressed store, hash-verified

146
147// OPT: tryPut is an optimized variant of the at/put pair used by setTableAt to avoid hashing the key twice.
148func (t *table) tryPut(l *State, k, v value) bool {
149 switch k := k.(type) {
150 case nil:
151 case float64:
152 if i := int(k); float64(i) == k && 0 < i && i <= len(t.array) && t.array[i-1] != nil {
153 t.array[i-1] = v
154 return true
155 } else if math.IsNaN(k) {
156 return false
157 } else if t.hash[k] != nil && v != nil {
158 t.hash[k] = v
159 return true
160 }
161 case string:
162 if t.hash[k] != nil && v != nil {
163 t.hash[k] = v
164 return true
165 }
166 default:
167 if t.hash[k] != nil && v != nil {
168 t.hash[k] = v
169 return true
170 }
171 }
172 return false
173}
174
175func (t *table) unboundSearch(j int) int {
176 i := j

Callers 1

setTableAtMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected