-
Notifications
You must be signed in to change notification settings - Fork 445
ChatContainer: avoid allocation of ArrayList #931
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
base: master
Are you sure you want to change the base?
Conversation
The chatRoomList is added in the synchronized addChatRoom() so removing of the fields also should be synchronized
|
It looks like some pattern or remains after some refactoring because there are other places with such iteration over an ArrayList copy: |
|
Does that mean that this should go to draft, or should this be tackled in another PR? |
… Features.NAMESPACE
…ners and fileDropListeners
Make it similar to getContactItems() that returns a sorted copy. Remove ContactList.ContactItemComparator as it's the same as the ContactGroup.itemComparator. Remove sorting of the group.getOfflineContacts() results in the BroadcastDialog()
…reduce new ArrayList(getContactItems())
…ationListeners) since getInvitationListeners() reruns an unmodifiable list
|
It creates a copy of the list (new ArrayList<>(this.presenceListeners)) to avoid concurrent modification issues if a listener modifies the list during iteration. I can't replace all the places where this happens but for listeners we have a few options:
The CopyOnWriteArrayList is already used in some places for listeners also an AI recommended to use it. So I changed all the places where I found a list of listeners to the CopyOnWriteArrayList so that same pattern will be used everywhere. I can't properly test it but Sparks looks working fine. |
The allocation might be needed (I guess) to avoid concurrency problems. The
chatRoomListis changed in two places: in theaddChatRoom()that is synchronized andcleanupChatRoom()that is not synchronized. So just to be sure I made it synchronized too.