feat: reduce obfs gc overhead by reusing buffers

This commit is contained in:
Toby
2021-12-23 17:25:11 -08:00
parent 8bd5573c93
commit 9e5483c11b
6 changed files with 83 additions and 80 deletions

View File

@@ -20,11 +20,11 @@ func TestXPlusObfuscator(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
bs := x.Obfuscate(tt.p)
outBs := make([]byte, len(bs))
n := x.Deobfuscate(bs, outBs)
if !bytes.Equal(tt.p, outBs[:n]) {
t.Errorf("Inconsistent deobfuscate result: got %v, want %v", outBs[:n], tt.p)
buf := make([]byte, 10240)
n := x.Obfuscate(tt.p, buf)
n2 := x.Deobfuscate(buf[:n], buf[n:])
if !bytes.Equal(tt.p, buf[n:n+n2]) {
t.Errorf("Inconsistent deobfuscate result: got %v, want %v", buf[n:n+n2], tt.p)
}
})
}