From 5b2a36579e53c69f154288a91ddc3e7c5375d7a6 Mon Sep 17 00:00:00 2001 From: bptato Date: Sat, 14 Sep 2024 15:58:52 +0200 Subject: loader: refactor, misc optimizations & fixes * factor out input/output handle tables; use a seq instead * add possibility to directly open cached items onto stdin (mainly an optimization for reading images, which are always cached) * close used handles on local CGI execution * make clone during load work again --- src/html/dom.nim | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) (limited to 'src/html') diff --git a/src/html/dom.nim b/src/html/dom.nim index b31802bc..146056a9 100644 --- a/src/html/dom.nim +++ b/src/html/dom.nim @@ -4565,6 +4565,7 @@ proc getContext*(jctx: JSContext; this: HTMLCanvasElement; contextId: string; # backwards compat, but I don't care. proc toBlob(ctx: JSContext; this: HTMLCanvasElement; callback: JSValue; contentType = "image/png"; quality = none(float64)) {.jsfunc.} = + let contentType = contentType.toLowerAscii() if not contentType.startsWith("image/") or this.bitmap.cacheId == 0: return let url0 = newURL("img-codec+" & contentType.after('/') & ":encode") @@ -4582,21 +4583,11 @@ proc toBlob(ctx: JSContext; this: HTMLCanvasElement; callback: JSValue; let callback = JS_DupValue(ctx, callback) let window = this.document.window let loader = window.loader - let contentType = contentType.toLowerAscii() - let cacheReq = newRequest(newURL("cache:" & $this.bitmap.cacheId).get) - loader.fetch(cacheReq).then(proc(res: JSResult[Response]): FetchPromise = - if res.isNone: - return newResolvedPromise(res) - let res = res.get - let p = loader.fetch(newRequest( - newURL("img-codec+x-cha-canvas:decode").get, - httpMethod = hmPost, - body = RequestBody(t: rbtOutput, outputId: res.outputId) - )) - res.resume() - res.close() - return p - ).then(proc(res: JSResult[Response]): FetchPromise = + loader.fetch(newRequest( + newURL("img-codec+x-cha-canvas:decode").get, + httpMethod = hmPost, + body = RequestBody(t: rbtCache, cacheId: this.bitmap.cacheId) + )).then(proc(res: JSResult[Response]): FetchPromise = if res.isNone: return newResolvedPromise(res) let res = res.get -- cgit 1.4.1-2-gfad0