From fe316e9dcbfad4be24042ab40ecec7613723697e Mon Sep 17 00:00:00 2001 From: Julien Oculi Date: Mon, 5 Feb 2024 15:31:57 +0100 Subject: [PATCH] perf: prevent stack overflow when concat buffer --- plugins/css_bundler/src/bundler.ts | 4 ++-- plugins/css_bundler/src/helpers.ts | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/plugins/css_bundler/src/bundler.ts b/plugins/css_bundler/src/bundler.ts index e9c5d37..22469ec 100644 --- a/plugins/css_bundler/src/bundler.ts +++ b/plugins/css_bundler/src/bundler.ts @@ -1,6 +1,6 @@ import { fromFileUrl, join } from '$std/path/mod.ts' import { builder } from './builder.ts' -import { cssImports, Logger } from './helpers.ts' +import { cssImports, Logger, uInt8ArrayConcat } from './helpers.ts' export async function bundleCss( sourceDir: string, @@ -24,7 +24,7 @@ export async function bundleCss( ) await Deno.writeFile( join(assetDir, pathname), - Uint8Array.of(...code, ...sourceMappingURL), + uInt8ArrayConcat(code, sourceMappingURL), ) await Deno.writeFile( diff --git a/plugins/css_bundler/src/helpers.ts b/plugins/css_bundler/src/helpers.ts index 070728a..9f55cda 100644 --- a/plugins/css_bundler/src/helpers.ts +++ b/plugins/css_bundler/src/helpers.ts @@ -26,3 +26,10 @@ export async function hashFile(file: ArrayBuffer): Promise { } export const cssImports: Map = new Map() + +export function uInt8ArrayConcat(a: Uint8Array, b: Uint8Array) { + const dest = new Uint8Array(a.length + b.length) + dest.set(a) + dest.set(b, a.length) + return dest +}