perf: dont use cloned array, iterate backwards

This commit is contained in:
Lewis Crichton 2023-12-31 01:10:32 +00:00
parent 6a3c592d5f
commit 02272c5b46
No known key found for this signature in database

View file

@ -66,11 +66,11 @@ async function initThemes() {
const links: string[] = [...themeLinks]; const links: string[] = [...themeLinks];
const enabledThemesClone = enabledThemes.slice();
if (IS_WEB) { if (IS_WEB) {
// make copy so we can remove themes that are missing // make copy so we can remove themes that are missing
for (const theme of enabledThemesClone) { for (let i = enabledThemes.length - 1; i >= 0; i--) {
const theme = enabledThemes[i];
try { try {
var themeData = await VencordNative.themes.getThemeData(theme); var themeData = await VencordNative.themes.getThemeData(theme);
} catch (e) { } catch (e) {
@ -87,7 +87,11 @@ async function initThemes() {
links.push(URL.createObjectURL(blob)); links.push(URL.createObjectURL(blob));
} }
} else { } else {
for (const theme of enabledThemesClone) if (!theme.endsWith(".user.css")) { for (let i = enabledThemes.length - 1; i >= 0; i--) {
const theme = enabledThemes[i];
if (theme.endsWith(".user.css")) continue;
try { try {
// whilst this is unnecessary here, we're doing it to make sure the theme is valid // whilst this is unnecessary here, we're doing it to make sure the theme is valid
await VencordNative.themes.getThemeData(theme); await VencordNative.themes.getThemeData(theme);
@ -102,7 +106,11 @@ async function initThemes() {
} }
if (!IS_WEB || "armcord" in window) { if (!IS_WEB || "armcord" in window) {
for (const theme of enabledThemesClone) if (theme.endsWith(".user.css")) { for (let i = enabledThemes.length - 1; i >= 0; i--) {
const theme = enabledThemes[i];
if (!theme.endsWith(".user.css")) continue;
// UserCSS goes through a compile step first // UserCSS goes through a compile step first
const css = await compileUsercss(theme); const css = await compileUsercss(theme);
if (!css) { if (!css) {