From 81ae5e6b5e198d8faf90d539c35b9fc872be7062 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 28 Jul 2026 23:45:37 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Optimize=20string=20splitting=20for?= =?UTF-8?q?=20title=20extraction?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replaced `.split("\n")` with an iterative `indexOf("\n")` approach in `titleFromContent`. This avoids scanning the entire string and allocating a large array of strings when extracting the title, which is especially impactful for large documents. Co-authored-by: Horizontal42 <75383519+Horizontal42@users.noreply.github.com> --- package-lock.json | 4 ++-- src/main.ts | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index 438d3d1..08a992f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "summarum", - "version": "1.2.1", + "version": "1.2.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "summarum", - "version": "1.2.1", + "version": "1.2.2", "dependencies": { "@codemirror/autocomplete": "^6.18.0", "@codemirror/commands": "^6.8.0", diff --git a/src/main.ts b/src/main.ts index d0bedf1..499cc49 100644 --- a/src/main.ts +++ b/src/main.ts @@ -50,9 +50,13 @@ function activeDoc(): DocMeta { } function titleFromContent(text: string): string { - for (const line of text.split("\n")) { - const s = line.trim(); + let start = 0; + while (start < text.length) { + let end = text.indexOf("\n", start); + if (end === -1) end = text.length; + const s = text.slice(start, end).trim(); if (s.length > 0) return s.replace(/^#\s*/, "").slice(0, 30); + start = end + 1; } return t("untitled"); }