From 9ec0a1d9281adb02c59bd748b8afd06367715305 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 17 Apr 2026 20:06:08 +0000 Subject: [PATCH] perf: Extract regex literals in movie helper mapping Extracted the whitespace cleanup regex `(\r\n|\n|\r|\t)/gm` to a module-level constant `CLEAN_TEXT_REGEX` in `src/helpers/movie.helper.ts`. This prevents redundant `RegExp` object allocation and compilation on every iteration when traversing `triviaNodes` and `movie` description paragraphs in `getMovieTrivia` and `getMovieDescriptions`. Co-authored-by: bartholomej <5861310+bartholomej@users.noreply.github.com> --- src/helpers/movie.helper.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/helpers/movie.helper.ts b/src/helpers/movie.helper.ts index 1cc2f8da..fe5b2a7e 100644 --- a/src/helpers/movie.helper.ts +++ b/src/helpers/movie.helper.ts @@ -28,6 +28,10 @@ import { parseLastIdFromUrl } from './global.helper'; +// Performance Optimization: Extract regex literal from loop map callbacks +// This avoids redundant recompilation per iteration. +const CLEAN_TEXT_REGEX = /(\r\n|\n|\r|\t)/gm; + const CREATOR_LABELS: Record< string, Record @@ -264,7 +268,7 @@ export const getMovieRandomPhoto = (el: HTMLElement | null): string => { export const getMovieTrivia = (el: HTMLElement | null): string[] => { const triviaNodes = el.querySelectorAll('.article-trivia ul li'); if (triviaNodes?.length) { - return triviaNodes.map((node) => node.textContent.trim().replace(/(\r\n|\n|\r|\t)/gm, '')); + return triviaNodes.map((node) => node.textContent.trim().replace(CLEAN_TEXT_REGEX, '')); } else { return null; } @@ -273,7 +277,7 @@ export const getMovieTrivia = (el: HTMLElement | null): string[] => { export const getMovieDescriptions = (el: HTMLElement): string[] => { return el .querySelectorAll('.body--plots .plot-full p, .body--plots .plots .plots-item p') - .map((movie) => movie.textContent?.trim().replace(/(\r\n|\n|\r|\t)/gm, '')); + .map((movie) => movie.textContent?.trim().replace(CLEAN_TEXT_REGEX, '')); }; const parseMoviePeople = (el: HTMLElement): CSFDMovieCreator[] => {