Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 6dd6a76

Browse files
authored
Decrypt events in reverse order without copying the array (#12445)
Signed-off-by: Johannes Marbach <[email protected]>
1 parent cc7edad commit 6dd6a76

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

Diff for: src/components/structures/TimelinePanel.tsx

+5-10
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ import dis from "../../dispatcher/dispatcher";
5454
import { Action } from "../../dispatcher/actions";
5555
import Timer from "../../utils/Timer";
5656
import shouldHideEvent from "../../shouldHideEvent";
57-
import { arrayFastClone } from "../../utils/arrays";
5857
import MessagePanel from "./MessagePanel";
5958
import { IScrollState } from "./ScrollPanel";
6059
import { ActionPayload } from "../../dispatcher/payloads";
@@ -1754,15 +1753,11 @@ class TimelinePanel extends React.Component<IProps, IState> {
17541753
[...mainEvents],
17551754
);
17561755

1757-
// `arrayFastClone` performs a shallow copy of the array
1758-
// we want the last event to be decrypted first but displayed last
1759-
// `reverse` is destructive and unfortunately mutates the "events" array
1760-
arrayFastClone(events)
1761-
.reverse()
1762-
.forEach((event) => {
1763-
const client = MatrixClientPeg.safeGet();
1764-
client.decryptEventIfNeeded(event);
1765-
});
1756+
// We want the last event to be decrypted first
1757+
const client = MatrixClientPeg.safeGet();
1758+
for (let i = events.length - 1; i >= 0; --i) {
1759+
client.decryptEventIfNeeded(events[i]);
1760+
}
17661761

17671762
const firstVisibleEventIndex = this.checkForPreJoinUISI(events);
17681763

0 commit comments

Comments
 (0)