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

mlange-42 / ark / 13700334370

06 Mar 2025 01:56PM CUT coverage: 99.317% (-0.06%) from 99.381%
13700334370

Pull #146

github

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

87 of 89 new or added lines in 7 files covered. (97.75%)

21 existing lines in 3 files now uncovered.

6252 of 6295 relevant lines covered (99.32%)

29953.43 hits per line

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

93.44
/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
        cap        uint32         // capacity
17
}
18

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

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

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

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

48
// Set overwrites the component at the given index.
49
func (c *column) Set(index uint32, comp unsafe.Pointer) unsafe.Pointer {
1,027,420✔
50
        dst := c.Get(uintptr(index))
1,027,420✔
51
        if c.itemSize == 0 {
1,028,546✔
52
                return dst
1,126✔
53
        }
1,126✔
54

55
        copyPtr(comp, dst, uintptr(c.itemSize))
1,026,294✔
56
        return dst
1,026,294✔
57
}
58

59
// Zero resets the memory at the given index.
60
func (c *column) Zero(index uintptr, zero unsafe.Pointer) {
508,499✔
61
        if c.itemSize == 0 {
508,720✔
62
                return
221✔
63
        }
221✔
64
        dst := unsafe.Add(c.pointer, index*c.itemSize)
508,278✔
65
        copyPtr(zero, dst, uintptr(c.itemSize))
508,278✔
66
}
67

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

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