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

mlange-42 / ark / 15069997160

16 May 2025 01:48PM CUT coverage: 99.832%. Remained the same
15069997160

Pull #245

github

web-flow
Merge 9f5dff38a into 88334f598
Pull Request #245: GC bug: runtime: marked free object in span

22 of 22 new or added lines in 4 files covered. (100.0%)

8314 of 8328 relevant lines covered (99.83%)

18415.54 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 table.
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 {
7,377✔
20
        // TODO: should we use a slice instead of an array here?
7,377✔
21
        data := reflect.New(reflect.ArrayOf(int(capacity), tp)).Elem()
7,377✔
22
        pointer := data.Addr().UnsafePointer()
7,377✔
23

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

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

39
func (c *column) SetLast(other *column, ownLen uint32, count uint32) {
463✔
40
        start := ownLen - count
463✔
41
        copyRange(other.data, c.data, int(start), int(count))
463✔
42
}
463✔
43

44
// Set overwrites the component at the given index.
45
func (c *column) Set(index uint32, src *column, srcIndex int) {
4,883✔
46
        if c.itemSize == 0 {
4,939✔
47
                return
56✔
48
        }
56✔
49
        copyItem(src.data, c.data, srcIndex, int(index))
4,827✔
50
}
51

52
// Zero resets the memory at the given index.
53
func (c *column) Zero(index uintptr, zero unsafe.Pointer) {
502,253✔
54
        if c.itemSize == 0 {
502,482✔
55
                return
229✔
56
        }
229✔
57
        dst := unsafe.Add(c.pointer, index*c.itemSize)
502,024✔
58
        copyPtr(zero, dst, uintptr(c.itemSize))
502,024✔
59
}
60

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

74
func (c *column) Reset(ownLen uint32, zero unsafe.Pointer) {
889✔
75
        if ownLen == 0 {
892✔
76
                return
3✔
77
        }
3✔
78
        if ownLen <= 64 { // A coarse estimate where manually zeroing is faster
1,762✔
79
                c.ZeroRange(0, ownLen, zero)
876✔
80
        } else {
886✔
81
                c.data.SetZero()
10✔
82
        }
10✔
83
}
84

85
// entityColumn storage for entities in an table.
86
type entityColumn struct {
87
        pointer unsafe.Pointer // pointer to the first element
88
        data    reflect.Value  // data buffer
89
}
90

91
// newColumn creates a new column for a given type and capacity.
92
func newEntityColumn(capacity uint32) entityColumn {
2,832✔
93
        // TODO: should we use a slice instead of an array here?
2,832✔
94
        data := reflect.New(reflect.ArrayOf(int(capacity), entityType)).Elem()
2,832✔
95
        pointer := data.Addr().UnsafePointer()
2,832✔
96

2,832✔
97
        return entityColumn{
2,832✔
98
                data:    data,
2,832✔
99
                pointer: pointer,
2,832✔
100
        }
2,832✔
101
}
2,832✔
102

103
// Get returns a pointer to the component at the given index.
104
func (c *entityColumn) Get(index uintptr) unsafe.Pointer {
1,989,271✔
105
        return unsafe.Add(c.pointer, index*entitySize)
1,989,271✔
106
}
1,989,271✔
107

108
func (c *entityColumn) SetLast(other *entityColumn, ownLen uint32, count uint32) {
215✔
109
        start := ownLen - count
215✔
110
        copyRange(other.data, c.data, int(start), int(count))
215✔
111
}
215✔
112

113
// Set overwrites the component at the given index.
114
func (c *entityColumn) Set(index uint32, comp unsafe.Pointer) unsafe.Pointer {
504,558✔
115
        dst := c.Get(uintptr(index))
504,558✔
116

504,558✔
117
        copyPtr(comp, dst, entitySize)
504,558✔
118
        return dst
504,558✔
119
}
504,558✔
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