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

mlange-42 / ark / 13943453453

19 Mar 2025 09:44AM CUT coverage: 99.808% (-0.02%) from 99.831%
13943453453

Pull #216

github

web-flow
Merge 8f89af148 into 59a28b100
Pull Request #216: Use a dedicates column type for entities in tables

26 of 26 new or added lines in 2 files covered. (100.0%)

2 existing lines in 1 file now uncovered.

8299 of 8315 relevant lines covered (99.81%)

20713.09 hits per line

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

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

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

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

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

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

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

57
// Zero resets the memory at the given index.
58
func (c *column) Zero(index uintptr, zero unsafe.Pointer) {
509,544✔
59
        if c.itemSize == 0 {
509,773✔
60
                return
229✔
61
        }
229✔
62
        dst := unsafe.Add(c.pointer, index*c.itemSize)
509,315✔
63
        copyPtr(zero, dst, uintptr(c.itemSize))
509,315✔
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) {
889✔
80
        if ownLen == 0 {
892✔
81
                return
3✔
82
        }
3✔
83
        if zero == nil {
886✔
UNCOV
84
                return
×
UNCOV
85
        }
×
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
}
92

93
// entityColumn storage for entities in an table.
94
type entityColumn struct {
95
        pointer unsafe.Pointer // pointer to the first element
96
        data    reflect.Value  // data buffer
97
}
98

99
// newColumn creates a new column for a given type and capacity.
100
func newEntityColumn(capacity uint32) entityColumn {
826✔
101
        // TODO: should be use a slice instead of an array here?
826✔
102
        data := reflect.New(reflect.ArrayOf(int(capacity), entityType)).Elem()
826✔
103
        pointer := data.Addr().UnsafePointer()
826✔
104

826✔
105
        return entityColumn{
826✔
106
                data:    data,
826✔
107
                pointer: pointer,
826✔
108
        }
826✔
109
}
826✔
110

111
// Get returns a pointer to the component at the given index.
112
func (c *entityColumn) Get(index uintptr) unsafe.Pointer {
3,032,320✔
113
        return unsafe.Add(c.pointer, index*entitySize)
3,032,320✔
114
}
3,032,320✔
115

116
func (c *entityColumn) SetLast(other *entityColumn, ownLen uint32, count uint32) {
215✔
117
        start := ownLen - count
215✔
118
        src := other.Get(0)
215✔
119
        dst := c.Get(uintptr(start))
215✔
120
        copyPtr(src, dst, entitySize*uintptr(count))
215✔
121
}
215✔
122

123
// Set overwrites the component at the given index.
124
func (c *entityColumn) Set(index uint32, comp unsafe.Pointer) unsafe.Pointer {
510,997✔
125
        dst := c.Get(uintptr(index))
510,997✔
126

510,997✔
127
        copyPtr(comp, dst, entitySize)
510,997✔
128
        return dst
510,997✔
129
}
510,997✔
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