From 9f9f602ad70ad2531ac255c705113a85bec1b452 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sat, 22 Aug 2026 00:41:08 +0000 Subject: [PATCH] perf: optimize word count logic with regex match Replaced inefficient `content.split(/\s+/).filter(Boolean).length` with `(content.match(/\S+/g) || []).length` in both `extension/content/extractor-core.js` and `extension/content/extractor.js`. The original method created multiple intermediate arrays causing unnecessary CPU and memory overhead, whereas the new regex directly counts matching words. Co-authored-by: savvides <1580637+savvides@users.noreply.github.com> --- extension/content/extractor-core.js | 2 +- extension/content/extractor.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/extension/content/extractor-core.js b/extension/content/extractor-core.js index 897bfa6..35af7e2 100644 --- a/extension/content/extractor-core.js +++ b/extension/content/extractor-core.js @@ -35,7 +35,7 @@ export function extractContentFromDOM(document, url = (typeof window !== 'undefi title, pageType, content: content.slice(0, 15000), - wordCount: content.split(/\s+/).filter(Boolean).length + wordCount: (content.match(/\S+/g) || []).length }; } diff --git a/extension/content/extractor.js b/extension/content/extractor.js index 9d72934..d59b9f5 100644 --- a/extension/content/extractor.js +++ b/extension/content/extractor.js @@ -38,7 +38,7 @@ function extractContentFromDOM(document, url = (typeof window !== 'undefined' && title, pageType, content: content.slice(0, 15000), - wordCount: content.split(/\s+/).filter(Boolean).length + wordCount: (content.match(/\S+/g) || []).length }; }