Reduce use of binary.Read and, by extention, reflection

This commit is contained in:
Caleb Gardner
2025-04-10 06:26:41 -05:00
parent 4490fc3873
commit 6b0e9ef2c6
8 changed files with 75 additions and 36 deletions
+1 -3
View File
@@ -1,7 +1,6 @@
package data
import (
"encoding/binary"
"errors"
"io"
"io/fs"
@@ -10,7 +9,6 @@ import (
"sync"
"github.com/CalebQ42/squashfs/internal/decompress"
"github.com/CalebQ42/squashfs/internal/toreader"
)
type FragReaderConstructor func() (io.Reader, error)
@@ -80,7 +78,7 @@ func (r FullReader) process(index uint64, fileOffset uint64, pool *sync.Pool, re
return
}
ret.data = make([]byte, realSize)
ret.err = binary.Read(toreader.NewReader(r.r, int64(r.initialOffset)+int64(fileOffset)), binary.LittleEndian, &ret.data)
_, ret.err = r.r.ReadAt(ret.data, r.initialOffset+int64(fileOffset))
if r.sizes[index] == realSize {
ret.data, ret.err = r.d.Decompress(ret.data)
}
+1 -2
View File
@@ -1,7 +1,6 @@
package data
import (
"encoding/binary"
"io"
"io/fs"
@@ -56,7 +55,7 @@ func (r *Reader) advance() error {
return nil
}
r.dat = make([]byte, realSize)
err = binary.Read(r.r, binary.LittleEndian, &r.dat)
_, err = r.r.Read(r.dat)
if err != nil {
return err
}