diff options
author | bptato <nincsnevem662@gmail.com> | 2024-02-13 21:27:31 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-02-13 21:32:49 +0100 |
commit | 93839580256029c298d469cb6999cf087a675108 (patch) | |
tree | f16f698d7aebc9fd7562e4b7e480dd69b213a948 /src/server | |
parent | 4e690f150c8e3e2a54661f7a5cbdf7df40718c73 (diff) | |
download | chawan-93839580256029c298d469cb6999cf087a675108.tar.gz |
buffer: skip rewind after the first read
Speeds up processing of pretty much all documents, because we rarely need to switch the charset after having downloaded the first chunk.
Diffstat (limited to 'src/server')
-rw-r--r-- | src/server/buffer.nim | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/src/server/buffer.nim b/src/server/buffer.nim index 4d0b829b..d830029b 100644 --- a/src/server/buffer.nim +++ b/src/server/buffer.nim @@ -119,6 +119,7 @@ type uastyle: CSSStylesheet quirkstyle: CSSStylesheet htmlParser: HTML5ParserWrapper + firstBufferRead: bool InterfaceOpaque = ref object stream: Stream @@ -815,7 +816,7 @@ proc connect2*(buffer: Buffer) {.proxy.} = # Notify loader that we can proceed with loading the input stream. buffer.istream.swrite(false) buffer.istream.swrite(true) - buffer.istream.setBlocking(false) + buffer.istream.setBlocking(false) buffer.selector.registerHandle(buffer.fd, {Read}, 0) proc redirectToFd*(buffer: Buffer, fd: FileHandle, wait, cache: bool) @@ -1088,19 +1089,28 @@ proc onload(buffer: Buffer) = return of LOADING_PAGE: discard + var reprocess = false while true: buffer.sstream.setPosition(0) - buffer.sstream.data.setLen(BufferSize) + if not reprocess: + buffer.sstream.data.setLen(BufferSize) try: - buffer.sstream.data.prepareMutation() - let n = buffer.istream.readData(addr buffer.sstream.data[0], BufferSize) - if n != buffer.sstream.data.len: - buffer.sstream.data.setLen(n) - if n != 0: + var n = 0 + if not reprocess: + buffer.sstream.data.prepareMutation() + n = buffer.istream.readData(addr buffer.sstream.data[0], BufferSize) + if n != buffer.sstream.data.len: + buffer.sstream.data.setLen(n) + if n != 0 or reprocess: buffer.available += n if not buffer.processData(): + if not buffer.firstBufferRead: + reprocess = true + continue if buffer.rewind(): continue + buffer.firstBufferRead = true + reprocess = false res.bytes = buffer.available res.lines = buffer.lines.len if buffer.istream.atEnd(): |