1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-22 14:22:05 +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;
if (!stanzaAcknowledgedListeners.isEmpty()) {
// If stanzaAcknowledgedListeners is not empty, the we have at least one
atLeastOneStanzaAcknowledgedListener = true;
}
else {
// Otherwise we look for a matching id in the stanza *id* acknowledged listeners
for (Packet ackedStanza : ackedStanzas) { for (Packet ackedStanza : ackedStanzas) {
String id = ackedStanza.getPacketID(); String id = ackedStanza.getPacketID();
if (id != null && stanzaAcknowledgedListeners.contains(id)) { if (id != null && stanzaIdAcknowledgedListeners.containsKey(id)) {
atLeastOneStanzaIdAcknowledgedListener = true; atLeastOneStanzaAcknowledgedListener = true;
break; 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() {