• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mlange-42 / ark / 13877142047

15 Mar 2025 10:17PM CUT coverage: 99.785%. Remained the same
13877142047

push

github

web-flow
Fix table recycling bug (#204)

11 of 11 new or added lines in 1 file covered. (100.0%)

8353 of 8371 relevant lines covered (99.78%)

20756.84 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/ecs/column.go
1
package ecs
2

3
import (
4
        "reflect"
5
        "unsafe"
6
)
7

8
// column storage for components in an archetype.
9
type column struct {
10
        pointer    unsafe.Pointer // pointer to the first element
11
        data       reflect.Value  // data buffer
12
        itemSize   uintptr        // memory size of items
13
        target     Entity         // target entity if for a relation component
14
        index      uint32         // index of the column in the containing table
15
        isRelation bool           // whether this column is for a relation component
16
}
17

18
// newColumn creates a new column for a given type and capacity.
19
func newColumn(index uint32, tp reflect.Type, itemSize uintptr, isRelation bool, target Entity, capacity uint32) column {
3,202✔
20
        // TODO: should be use a slice instead of an array here?
3,202✔
21
        data := reflect.New(reflect.ArrayOf(int(capacity), tp)).Elem()
3,202✔
22
        pointer := data.Addr().UnsafePointer()
3,202✔
23

3,202✔
24
        return column{
3,202✔
25
                index:      index,
3,202✔
26
                data:       data,
3,202✔
27
                pointer:    pointer,
3,202✔
28
                itemSize:   itemSize,
3,202✔
29
                isRelation: isRelation,
3,202✔
30
                target:     target,
3,202✔
31
        }
3,202✔
32
}
3,202✔
33

34
// Get returns a pointer to the component at the given index.
35
func (c *column) Get(index uintptr) unsafe.Pointer {
5,132,083✔
36
        return unsafe.Add(c.pointer, index*c.itemSize)
5,132,083✔
37
}
5,132,083✔
38

39
func (c *column) SetLast(other *column, ownLen uint32, count uint32) {
679✔
40
        start := ownLen - count
679✔
41
        src := other.Get(0)
679✔
42
        dst := c.Get(uintptr(start))
679✔
43
        copyPtr(src, dst, c.itemSize*uintptr(count))
679✔
44
}
679✔
45

46
// Set overwrites the component at the given index.
47
func (c *column) Set(index uint32, comp unsafe.Pointer) unsafe.Pointer {
1,033,036✔
48
        dst := c.Get(uintptr(index))
1,033,036✔
49
        if c.itemSize == 0 {
1,034,382✔
50
                return dst
1,346✔
51
        }
1,346✔
52

53
        copyPtr(comp, dst, uintptr(c.itemSize))
1,031,690✔
54
        return dst
1,031,690✔
55
}
56

57
// Zero resets the memory at the given index.
58
func (c *column) Zero(index uintptr, zero unsafe.Pointer) {
508,427✔
59
        if c.itemSize == 0 {
508,652✔
60
                return
225✔
61
        }
225✔
62
        dst := unsafe.Add(c.pointer, index*c.itemSize)
508,202✔
63
        copyPtr(zero, dst, uintptr(c.itemSize))
508,202✔
64
}
65

66
// Zero resets a block of storage in one buffer.
67
func (c *column) ZeroRange(start, len uint32, zero unsafe.Pointer) {
876✔
68
        size := uint32(c.itemSize)
876✔
69
        if size == 0 {
907✔
70
                return
31✔
71
        }
31✔
72
        var i uint32
845✔
73
        for i = 0; i < len; i++ {
11,934✔
74
                dst := unsafe.Add(c.pointer, (i+start)*size)
11,089✔
75
                copyPtr(zero, dst, c.itemSize)
11,089✔
76
        }
11,089✔
77
}
78

79
func (c *column) Reset(ownLen uint32, zero unsafe.Pointer) {
1,129✔
80
        if ownLen == 0 {
1,133✔
81
                return
4✔
82
        }
4✔
83
        if zero == nil {
1,364✔
84
                return
239✔
85
        }
239✔
86
        if ownLen <= 64 { // A coarse estimate where manually zeroing is faster
1,762✔
87
                c.ZeroRange(0, ownLen, zero)
876✔
88
        } else {
886✔
89
                c.data.SetZero()
10✔
90
        }
10✔
91
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc