mirror of
https://github.com/Horizontal42/summarum.git
synced 2026-11-11 01:02:01 +03:00
⚡ Optimize string splitting for title extraction
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>
This commit is contained in:
parent
f5b1fc038b
commit
81ae5e6b5e
2 changed files with 8 additions and 4 deletions
4
package-lock.json
generated
4
package-lock.json
generated
|
|
@ -1,12 +1,12 @@
|
||||||
{
|
{
|
||||||
"name": "summarum",
|
"name": "summarum",
|
||||||
"version": "1.2.1",
|
"version": "1.2.2",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "summarum",
|
"name": "summarum",
|
||||||
"version": "1.2.1",
|
"version": "1.2.2",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@codemirror/autocomplete": "^6.18.0",
|
"@codemirror/autocomplete": "^6.18.0",
|
||||||
"@codemirror/commands": "^6.8.0",
|
"@codemirror/commands": "^6.8.0",
|
||||||
|
|
|
||||||
|
|
@ -50,9 +50,13 @@ function activeDoc(): DocMeta {
|
||||||
}
|
}
|
||||||
|
|
||||||
function titleFromContent(text: string): string {
|
function titleFromContent(text: string): string {
|
||||||
for (const line of text.split("\n")) {
|
let start = 0;
|
||||||
const s = line.trim();
|
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);
|
if (s.length > 0) return s.replace(/^#\s*/, "").slice(0, 30);
|
||||||
|
start = end + 1;
|
||||||
}
|
}
|
||||||
return t("untitled");
|
return t("untitled");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue