Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update to huffman v2 - removes tree initialization nearly completely #24

Merged
merged 2 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module github.com/teeworlds-go/protocol

go 1.22.3

require github.com/teeworlds-go/huffman v1.0.0
require github.com/teeworlds-go/huffman/v2 v2.0.0
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
github.com/teeworlds-go/huffman v1.0.0 h1:XSNMNAJZb+njNrPACsxcDrrLDXTGjZZt35FqLAuHi4I=
github.com/teeworlds-go/huffman v1.0.0/go.mod h1:kjaXpL6C6xL7CM+tWPNYjdEgVZB2GumKhx7rCDdXArU=
github.com/teeworlds-go/huffman/v2 v2.0.0 h1:eWmQe6OZ7o6Qn75ErZ0UeM+fnT0Gz6XLx0dlO2AtJ4U=
github.com/teeworlds-go/huffman/v2 v2.0.0/go.mod h1:qrL61bcSz/NZ1mQyFjAOcbza7acJQj2ltwdjetLHsOY=
9 changes: 3 additions & 6 deletions protocol7/packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"slices"

"github.com/teeworlds-go/huffman"
"github.com/teeworlds-go/huffman/v2"
"github.com/teeworlds-go/protocol/chunk7"
"github.com/teeworlds-go/protocol/messages7"
"github.com/teeworlds-go/protocol/network7"
Expand Down Expand Up @@ -336,8 +336,7 @@ func (packet *Packet) Unpack(data []byte) (err error) {
if packet.Header.Flags.Compression {
// TODO: try avoiding repeated initialization of the huffman tree structure
// move this into the Packet struct or even further up
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this comment can be removed now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

huff := huffman.Huffman{}
payload, err = huff.Decompress(payload)
payload, err = huffman.Decompress(payload)
if err != nil {
return err
}
Expand Down Expand Up @@ -373,10 +372,8 @@ func (packet *Packet) Pack(connection *Session) []byte {
}

if packet.Header.Flags.Compression {
// TODO: store huffman object in connection to avoid reallocating memory
huff := huffman.Huffman{}
var err error
payload, err = huff.Compress(payload)
payload, err = huffman.Compress(payload)
if err != nil {
panic(err)
}
Expand Down
Loading