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

mlange-42 / ark / 13751358310

09 Mar 2025 06:32PM CUT coverage: 99.43%. Remained the same
13751358310

push

github

web-flow
Add Zenodo DOI and how to cite (#168)

6456 of 6493 relevant lines covered (99.43%)

27231.61 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
        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
}
16

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

2,467✔
23
        return column{
2,467✔
24
                data:       data,
2,467✔
25
                pointer:    pointer,
2,467✔
26
                itemSize:   sizeOf(tp),
2,467✔
27
                isRelation: isRelation,
2,467✔
28
                target:     target,
2,467✔
29
        }
2,467✔
30
}
2,467✔
31

32
// Get returns a pointer to the component at the given index.
33
func (c *column) Get(index uintptr) unsafe.Pointer {
4,870,751✔
34
        return unsafe.Add(c.pointer, index*c.itemSize)
4,870,751✔
35
}
4,870,751✔
36

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

44
// Set overwrites the component at the given index.
45
func (c *column) Set(index uint32, comp unsafe.Pointer) unsafe.Pointer {
988,057✔
46
        dst := c.Get(uintptr(index))
988,057✔
47
        if c.itemSize == 0 {
989,183✔
48
                return dst
1,126✔
49
        }
1,126✔
50

51
        copyPtr(comp, dst, uintptr(c.itemSize))
986,931✔
52
        return dst
986,931✔
53
}
54

55
// Zero resets the memory at the given index.
56
func (c *column) Zero(index uintptr, zero unsafe.Pointer) {
488,518✔
57
        if c.itemSize == 0 {
488,739✔
58
                return
221✔
59
        }
221✔
60
        dst := unsafe.Add(c.pointer, index*c.itemSize)
488,297✔
61
        copyPtr(zero, dst, uintptr(c.itemSize))
488,297✔
62
}
63

64
// Zero resets a block of storage in one buffer.
65
func (c *column) ZeroRange(start, len uint32, zero unsafe.Pointer) {
612✔
66
        size := uint32(c.itemSize)
612✔
67
        if size == 0 {
635✔
68
                return
23✔
69
        }
23✔
70
        var i uint32
589✔
71
        for i = 0; i < len; i++ {
8,074✔
72
                dst := unsafe.Add(c.pointer, (i+start)*size)
7,485✔
73
                copyPtr(zero, dst, c.itemSize)
7,485✔
74
        }
7,485✔
75
}
76

77
func (c *column) Reset(ownLen uint32, zero unsafe.Pointer) {
823✔
78
        if ownLen == 0 {
827✔
79
                return
4✔
80
        }
4✔
81
        if zero == nil {
1,018✔
82
                return
199✔
83
        }
199✔
84
        if ownLen <= 64 { // A coarse estimate where manually zeroing is faster
1,232✔
85
                c.ZeroRange(0, ownLen, zero)
612✔
86
        } else {
620✔
87
                c.data.SetZero()
8✔
88
        }
8✔
89
}
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