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
1 changed files with 14 additions and 7 deletions

View File

@ -1630,17 +1630,24 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
ackedStanzas.add(ackedStanza);
}
boolean atLeastOneStanzaIdAcknowledgedListener = false;
for (Packet ackedStanza : ackedStanzas) {
String id = ackedStanza.getPacketID();
if (id != null && stanzaAcknowledgedListeners.contains(id)) {
atLeastOneStanzaIdAcknowledgedListener = true;
break;
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) {
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
if (atLeastOneStanzaIdAcknowledgedListener || !stanzaAcknowledgedListeners.isEmpty()) {
if (atLeastOneStanzaAcknowledgedListener) {
asyncGo(new Runnable() {
@Override
public void run() {