MCPcopy Create free account
hub / github.com/dop251/goja / swap

Method swap

object_goarray_reflect.go:331–358  ·  view source on GitHub ↗
(i int, j int)

Source from the content-addressed store, hash-verified

329}
330
331func (o *objectGoArrayReflect) swap(i int, j int) {
332 vi := o.fieldsValue.Index(i)
333 vj := o.fieldsValue.Index(j)
334 tmp := reflect.New(o.fieldsValue.Type().Elem()).Elem()
335 tmp.Set(vi)
336 vi.Set(vj)
337 vj.Set(tmp)
338
339 cachedI := o.valueCache.get(i)
340 cachedJ := o.valueCache.get(j)
341 if cachedI != nil {
342 cachedI.setReflectValue(vj)
343 o.valueCache.put(j, cachedI)
344 } else {
345 if j < len(o.valueCache) {
346 o.valueCache[j] = nil
347 }
348 }
349
350 if cachedJ != nil {
351 cachedJ.setReflectValue(vi)
352 o.valueCache.put(i, cachedJ)
353 } else {
354 if i < len(o.valueCache) {
355 o.valueCache[i] = nil
356 }
357 }
358}

Callers

nothing calls this directly

Calls 5

NewMethod · 0.80
SetMethod · 0.65
getMethod · 0.65
setReflectValueMethod · 0.65
putMethod · 0.45

Tested by

no test coverage detected