diff options
author | Vincent Petry <vincent@nextcloud.com> | 2020-10-22 18:15:18 +0300 |
---|---|---|
committer | Vincent Petry <vincent@nextcloud.com> | 2020-10-22 18:15:18 +0300 |
commit | 9228196f5b8882ce8011c5b0dc71f14ee42675bf (patch) | |
tree | 14ad01ab53a455ca56ae8450e034ead714a879c8 /src | |
parent | a35132b5e3e083ac5ab3a291ff828fa9e43dbcd8 (diff) |
Don't copy array for reverse iteration
Copying an array just for the sake of reverse iteration is a bit
wasteful, especially with bigger arrays.
Signed-off-by: Vincent Petry <vincent@nextcloud.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/components/MessagesList/MessagesList.vue | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/src/components/MessagesList/MessagesList.vue b/src/components/MessagesList/MessagesList.vue index cfeb2fd37..340341d6d 100644 --- a/src/components/MessagesList/MessagesList.vue +++ b/src/components/MessagesList/MessagesList.vue @@ -596,14 +596,13 @@ export default { * @returns {string} The last known message id. */ getLastKnownMessageId() { - // Reverse a copy of the messages array - const reversedMessages = this.messagesList.slice().reverse() - // Get the id of the last non-temporary message - for (const message of reversedMessages) { - const id = message.id.toString() - if (!id.startsWith('temp-')) { - return id + let i = this.messagesList.length - 1 + + while (i >= 0) { + if (!this.messagesList[i].id.toString().startsWith('temp-')) { + return this.messagesList[i].id } + i-- } return '0' }, |