Skip to content

Commit 55ab60b

Browse files
committed
Optimize Write
Signed-off-by: Jim Ma <[email protected]>
1 parent c2e9411 commit 55ab60b

File tree

1 file changed

+12
-23
lines changed

1 file changed

+12
-23
lines changed

alg_linux.go

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ func (h *ihash) Close() error {
109109

110110
func (h *ihash) ReadFrom(r io.Reader) (int64, error) {
111111
if f, ok := r.(*os.File); ok {
112-
if w, err, handled := h.sendfile(f, -1); handled {
113-
return w, err
114-
}
112+
//if w, err, handled := h.sendfile(f, -1); handled {
113+
// return w, err
114+
//}
115115
if w, err, handled := h.splice(f, -1); handled {
116116
return w, err
117117
}
@@ -124,9 +124,9 @@ func (h *ihash) ReadFrom(r io.Reader) (int64, error) {
124124

125125
func (h *ihash) readFromLimitedReader(lr *io.LimitedReader) (int64, error) {
126126
if f, ok := lr.R.(*os.File); ok {
127-
if w, err, handled := h.sendfile(f, lr.N); handled {
128-
return w, err
129-
}
127+
//if w, err, handled := h.sendfile(f, lr.N); handled {
128+
// return w, err
129+
//}
130130
if w, err, handled := h.splice(f, lr.N); handled {
131131
return w, err
132132
}
@@ -224,24 +224,13 @@ func (h *ihash) sendfile(f *os.File, remain int64) (written int64, err error, ha
224224

225225
// Write writes data to an AF_ALG socket, but instructs the kernel
226226
// not to finalize the hash.
227-
func (h *ihash) Write(b []byte) (written int, err error) {
228-
for {
229-
n, err := h.pipes[1].Vmsplice(b, 0)
230-
written += n
231-
if err != nil {
232-
break
233-
}
234-
_, err = h.pipes[0].Splice(h.s.FD(), n, unix.SPLICE_F_MOVE|unix.SPLICE_F_MORE)
235-
if err != nil {
236-
break
237-
}
238-
if n >= len(b) {
239-
break
240-
}
241-
b = b[n:]
227+
func (h *ihash) Write(b []byte) (int, error) {
228+
n, err := h.pipes[1].Vmsplice(b, 0)
229+
if err != nil {
230+
return n, err
242231
}
243-
244-
return
232+
_, err = h.pipes[0].Splice(h.s.FD(), n, unix.SPLICE_F_MOVE|unix.SPLICE_F_MORE)
233+
return n, err
245234
}
246235

247236
// Sum reads data from an AF_ALG socket, and appends it to the input

0 commit comments

Comments
 (0)