From 6dd6a7697c2d09d9dd2d7803725bc8420a65b48c Mon Sep 17 00:00:00 2001 From: Johannes Marbach Date: Mon, 22 Apr 2024 10:52:50 +0200 Subject: [PATCH] Decrypt events in reverse order without copying the array (#12445) Signed-off-by: Johannes Marbach --- src/components/structures/TimelinePanel.tsx | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/components/structures/TimelinePanel.tsx b/src/components/structures/TimelinePanel.tsx index ba3c4d203b..288c65972f 100644 --- a/src/components/structures/TimelinePanel.tsx +++ b/src/components/structures/TimelinePanel.tsx @@ -54,7 +54,6 @@ import dis from "../../dispatcher/dispatcher"; import { Action } from "../../dispatcher/actions"; import Timer from "../../utils/Timer"; import shouldHideEvent from "../../shouldHideEvent"; -import { arrayFastClone } from "../../utils/arrays"; import MessagePanel from "./MessagePanel"; import { IScrollState } from "./ScrollPanel"; import { ActionPayload } from "../../dispatcher/payloads"; @@ -1754,15 +1753,11 @@ class TimelinePanel extends React.Component { [...mainEvents], ); - // `arrayFastClone` performs a shallow copy of the array - // we want the last event to be decrypted first but displayed last - // `reverse` is destructive and unfortunately mutates the "events" array - arrayFastClone(events) - .reverse() - .forEach((event) => { - const client = MatrixClientPeg.safeGet(); - client.decryptEventIfNeeded(event); - }); + // We want the last event to be decrypted first + const client = MatrixClientPeg.safeGet(); + for (let i = events.length - 1; i >= 0; --i) { + client.decryptEventIfNeeded(events[i]); + } const firstVisibleEventIndex = this.checkForPreJoinUISI(events);