Skip to content

Commit 25c4bf5

Browse files
authored
Merge branch 'master' into cs2-starting-weapons
2 parents 405d17c + 1c75df8 commit 25c4bf5

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

pkg/demoinfocs/s2_commands.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,11 @@ func (m *pendingMessage) priority() int {
298298

299299
func (p *parser) handleDemoPacket(pack *msgs2.CDemoPacket) {
300300
b := pack.GetData()
301+
302+
if len(b) == 0 {
303+
return
304+
}
305+
301306
r := bitread.NewSmallBitReader(bytes.NewReader(b))
302307

303308
ms := make([]pendingMessage, 0)

pkg/demoinfocs/sendtables2/class.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,17 @@ import (
77
st "github.com/markus-wa/demoinfocs-golang/v4/pkg/demoinfocs/sendtables"
88
)
99

10+
type fpNameTreeCache struct {
11+
next map[int]*fpNameTreeCache
12+
name string
13+
}
14+
1015
type class struct {
1116
classId int32
1217
name string
1318
serializer *serializer
1419
createdHandlers []st.EntityCreatedHandler
20+
fpNameCache *fpNameTreeCache
1521
}
1622

1723
func (c *class) ID() int {
@@ -72,7 +78,27 @@ func (c *class) collectFieldsEntries(fields []*field, prefix string) []string {
7278
}
7379

7480
func (c *class) getNameForFieldPath(fp *fieldPath) string {
75-
return strings.Join(c.serializer.getNameForFieldPath(fp, 0), ".")
81+
currentCacheNode := c.fpNameCache
82+
83+
for i := 0; i <= fp.last; i++ {
84+
if currentCacheNode.next == nil {
85+
currentCacheNode.next = make(map[int]*fpNameTreeCache)
86+
}
87+
88+
pos := fp.path[i]
89+
next, exists := currentCacheNode.next[pos]
90+
if !exists {
91+
next = &fpNameTreeCache{}
92+
currentCacheNode.next[pos] = next
93+
}
94+
currentCacheNode = next
95+
}
96+
97+
if currentCacheNode.name == "" {
98+
currentCacheNode.name = strings.Join(c.serializer.getNameForFieldPath(fp, 0), ".")
99+
}
100+
101+
return currentCacheNode.name
76102
}
77103

78104
func (c *class) getTypeForFieldPath(fp *fieldPath) *fieldType {

pkg/demoinfocs/sendtables2/parser.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ func (p *Parser) OnDemoClassInfo(m *msgs2.CDemoClassInfo) error {
126126
classId: classId,
127127
name: networkName,
128128
serializer: p.serializers[networkName],
129+
fpNameCache: &fpNameTreeCache{
130+
next: make(map[int]*fpNameTreeCache),
131+
},
129132
}
130133
p.classesById[class.classId] = class
131134
p.classesByName[class.name] = class

0 commit comments

Comments
 (0)