1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-10 18:15:58 +01:00

Improve XMPPTCPConnection.processHandledCount(long)

Add shortcut: If stanzaAcknowledgedListeners is not empty, then we don't
need to check the stanzaIdAcknowledgedListeners.

Also fixes a bug, instead of

if (id != null && stanzaAcknowledgedListeners.contains(id)) {

it must be

if (id != null && stanzaIdAcknowledgedListeners.containsKey(id)) {
This commit is contained in:
Florian Schmaus 2015-01-13 11:15:55 +01:00
parent 07539820c3
commit 24b940138f

View file

@ -1630,17 +1630,24 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
ackedStanzas.add(ackedStanza); ackedStanzas.add(ackedStanza);
} }
boolean atLeastOneStanzaIdAcknowledgedListener = false; boolean atLeastOneStanzaAcknowledgedListener = false;
for (Packet ackedStanza : ackedStanzas) { if (!stanzaAcknowledgedListeners.isEmpty()) {
String id = ackedStanza.getPacketID(); // If stanzaAcknowledgedListeners is not empty, the we have at least one
if (id != null && stanzaAcknowledgedListeners.contains(id)) { atLeastOneStanzaAcknowledgedListener = true;
atLeastOneStanzaIdAcknowledgedListener = true; }
break; else {
// Otherwise we look for a matching id in the stanza *id* acknowledged listeners
for (Packet ackedStanza : ackedStanzas) {
String id = ackedStanza.getPacketID();
if (id != null && stanzaIdAcknowledgedListeners.containsKey(id)) {
atLeastOneStanzaAcknowledgedListener = true;
break;
}
} }
} }
// Only spawn a new thread if there is a chance that some listener is invoked // Only spawn a new thread if there is a chance that some listener is invoked
if (atLeastOneStanzaIdAcknowledgedListener || !stanzaAcknowledgedListeners.isEmpty()) { if (atLeastOneStanzaAcknowledgedListener) {
asyncGo(new Runnable() { asyncGo(new Runnable() {
@Override @Override
public void run() { public void run() {