-
Notifications
You must be signed in to change notification settings - Fork 768
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix StackOverflowError while recording voice message [PSF-1065] #6222
Conversation
visibleBarHeights = visibleBarHeights.subList(visibleBarHeights.size - maxVisibleBarCount, visibleBarHeights.size) | ||
visibleBarHeights = mutableListOf<FFT>().apply { | ||
addAll(visibleBarHeights.subList(visibleBarHeights.size - maxVisibleBarCount, visibleBarHeights.size)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand that we want to keep the last maxVisibleBarCount
items on the list.
Can it be rewritten like this:
if (visibleBarHeights.size > maxVisibleBarCount) {
visibleBarHeights = visibleBarHeights.takeLast(maxVisibleBarCount).toMutableList()
// Or, but maybe less clear
visibleBarHeights = visibleBarHeights.drop(maxVisibleBarCount - visibleBarHeights.size).toMutableList()
}
Alternatively we could drop the first items like this:
while (visibleBarHeights.size > maxVisibleBarCount) {
visibleBarHeights.removeAt(0)
}
which has the advantage of not creating a new list. Also it should in fact only drop one item, each time we add an item and make the list too long.
To me those both suggestions are easier to read.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good ideas, thanks!
Matrix SDKIntegration Tests Results:
|
Type of change
Content
Motivation and context
Fixes #6137
Screenshots / GIFs
Tests
Tested devices
Checklist