about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-06-14 19:14:23 +0200
committerbptato <nincsnevem662@gmail.com>2024-06-14 19:14:23 +0200
commit79d4b5440c220a020c973bd80cb78754531ebb30 (patch)
treed8161b6f77aa4217b4099973bc6dff5a1bd5cb21 /src
parenteb108a4784b29f8b988856fd6a7ac5cc5cd19bb9 (diff)
downloadchawan-79d4b5440c220a020c973bd80cb78754531ebb30.tar.gz
buffer: copy less
Diffstat (limited to 'src')
-rw-r--r--src/server/buffer.nim18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/server/buffer.nim b/src/server/buffer.nim
index 223754e9..1d172922 100644
--- a/src/server/buffer.nim
+++ b/src/server/buffer.nim
@@ -722,9 +722,9 @@ proc do_reshape(buffer: Buffer) =
     buffer.images)
   buffer.prevStyled = styledRoot
 
-proc processData0(buffer: Buffer; data: openArray[char]): bool =
+proc processData0(buffer: Buffer; data: UnsafeSlice): bool =
   if buffer.ishtml:
-    if buffer.htmlParser.parseBuffer(data) == PRES_STOP:
+    if buffer.htmlParser.parseBuffer(data.toOpenArray()) == PRES_STOP:
       buffer.charsetStack = @[buffer.htmlParser.builder.charset]
       return false
   else:
@@ -735,12 +735,10 @@ proc processData0(buffer: Buffer; data: openArray[char]): bool =
       plaintext = buffer.document.findFirst(TAG_PLAINTEXT)
     if data.len > 0:
       let lastChild = plaintext.lastChild
-      var text = newString(data.len)
-      copyMem(addr text[0], unsafeAddr data[0], data.len)
       if lastChild != nil and lastChild of Text:
-        Text(lastChild).data &= text
+        Text(lastChild).data &= data
       else:
-        plaintext.insert(buffer.document.createTextNode(text), nil)
+        plaintext.insert(buffer.document.createTextNode($data), nil)
       plaintext.invalid = true
   true
 
@@ -784,7 +782,7 @@ proc processData(buffer: Buffer; iq: openArray[uint8]): bool =
   if not buffer.canSwitch():
     buffer.ctx.errorMode = demReplacement
   for chunk in buffer.ctx.decode(iq.toOpenArray(si, iq.high), finish = false):
-    if not buffer.processData0(chunk.toOpenArray()):
+    if not buffer.processData0(chunk):
       buffer.switchCharset()
       return false
   if buffer.ctx.failed:
@@ -1112,7 +1110,11 @@ proc finishLoad(buffer: Buffer): EmptyPromise =
     return p
   buffer.state = bsLoadingResources
   if buffer.ctx.td != nil and buffer.ctx.td.finish() == tdfrError:
-    doAssert buffer.processData0("\uFFFD")
+    var s = "\uFFFD"
+    doAssert buffer.processData0(UnsafeSlice(
+      p: cast[ptr UncheckedArray[char]](addr s[0]),
+      len: s.len
+    ))
   buffer.htmlParser.finish()
   buffer.document.readyState = rsInteractive
   buffer.dispatchDOMContentLoadedEvent()