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

mlange-42 / ark / 13700970930

06 Mar 2025 02:28PM CUT coverage: 99.316% (-0.07%) from 99.381%
13700970930

Pull #146

github

web-flow
Merge e072d193f into 30636e28f
Pull Request #146: Optimize table operations

94 of 94 new or added lines in 7 files covered. (100.0%)

4 existing lines in 1 file now uncovered.

6239 of 6282 relevant lines covered (99.32%)

29459.66 hits per line

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

93.33
/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
        data       reflect.Value  // data buffer
11
        pointer    unsafe.Pointer // pointer to the first element
12
        isRelation bool           // whether this column is for a relation component
13
        target     Entity         // target entity if for a relation component
14
        itemSize   uintptr        // memory size of items
15
        len        uint32         // number of items
16
}
17

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

2,390✔
24
        return column{
2,390✔
25
                data:       data,
2,390✔
26
                pointer:    pointer,
2,390✔
27
                itemSize:   sizeOf(tp),
2,390✔
28
                isRelation: isRelation,
2,390✔
29
                target:     target,
2,390✔
30
                len:        0,
2,390✔
31
        }
2,390✔
32
}
2,390✔
33

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

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

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

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

57
// Zero resets the memory at the given index.
58
func (c *column) Zero(index uintptr, zero unsafe.Pointer) {
499,910✔
59
        if c.itemSize == 0 {
500,131✔
60
                return
221✔
61
        }
221✔
62
        dst := unsafe.Add(c.pointer, index*c.itemSize)
499,689✔
63
        copyPtr(zero, dst, uintptr(c.itemSize))
499,689✔
64
}
65

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

79
func (c *column) Reset(zero unsafe.Pointer) {
771✔
80
        len := c.len
771✔
81
        if c.len == 0 {
771✔
UNCOV
82
                return
×
UNCOV
83
        }
×
84
        c.len = 0
771✔
85
        if zero == nil {
955✔
86
                return
184✔
87
        }
184✔
88
        if len <= 64 { // A coarse estimate where manually zeroing is faster
1,174✔
89
                c.ZeroRange(0, len, zero)
587✔
90
        } else {
587✔
UNCOV
91
                c.data.SetZero()
×
UNCOV
92
        }
×
93
}
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