diff options
author | bptato <nincsnevem662@gmail.com> | 2023-12-03 13:06:10 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2023-12-03 13:06:10 +0100 |
commit | df61c2f81c80bc771a36b07eb94d6c3f5b821b50 (patch) | |
tree | 8b2a2a0bf3f5ad929a4451e7d46dcd61eb2a06da /src/server/buffer.nim | |
parent | 7728bad57be566bd86327dc843f8b950d538a2f0 (diff) | |
download | chawan-df61c2f81c80bc771a36b07eb94d6c3f5b821b50.tar.gz |
buffer: do not needlessly copy in onload
Diffstat (limited to 'src/server/buffer.nim')
-rw-r--r-- | src/server/buffer.nim | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/src/server/buffer.nim b/src/server/buffer.nim index ce99a691..e69af1fb 100644 --- a/src/server/buffer.nim +++ b/src/server/buffer.nim @@ -815,8 +815,6 @@ proc connect2*(buffer: Buffer) {.proxy.} = let ss = SocketStream(buffer.istream) ss.swrite(false) ss.setBlocking(false) - buffer.istream = newTeeStream(buffer.istream, buffer.sstream, - closedest = false) buffer.selector.registerHandle(buffer.fd, {Read}, 0) proc redirectToFd*(buffer: Buffer, fd: FileHandle, wait: bool) {.proxy.} = @@ -864,8 +862,7 @@ proc readFromFd*(buffer: Buffer, fd: FileHandle, ishtml: bool) {.proxy.} = ) buffer.ishtml = ishtml discard fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) or O_NONBLOCK) - let ps = newPosixStream(fd) - buffer.istream = newTeeStream(ps, buffer.sstream, closedest = false) + buffer.istream = newPosixStream(fd) buffer.fd = fd buffer.selector.registerHandle(buffer.fd, {Read}, 0) @@ -957,8 +954,7 @@ proc clone*(buffer: Buffer, newurl: URL): Pid {.proxy.} = discard close(pipefd_write[1]) # close write buffer.fd = pipefd_write[0] buffer.selector.registerHandle(buffer.fd, {Read}, 0) - let ps = newPosixStream(pipefd_write[0]) - buffer.istream = newTeeStream(ps, buffer.sstream, closedest = false) + buffer.istream = newPosixStream(pipefd_write[0]) buffer.pstream.close() let ssock = initServerSocket(buffered = false) ps.write(char(0)) @@ -1119,16 +1115,16 @@ proc onload(buffer: Buffer) = of LOADING_PAGE: discard let op = buffer.sstream.getPosition() - var s = newString(buffer.readbufsize) + var s = newSeqUninitialized[uint8](buffer.readbufsize) try: buffer.sstream.setPosition(op + buffer.available) let n = buffer.istream.readData(addr s[0], buffer.readbufsize) if n != 0: # n can be 0 if we get EOF. (in which case we shouldn't reshape unnecessarily.) - s.setLen(n) + buffer.sstream.writeData(addr s[0], n) buffer.sstream.setPosition(op) if buffer.readbufsize < BufferSize: buffer.readbufsize = min(BufferSize, buffer.readbufsize * 2) - buffer.available += s.len + buffer.available += n if buffer.ishtml: res.bytes = buffer.available else: |