1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-25 15:52:06 +01:00

[core] Optimize Presence.toXML() for empty element

This commit is contained in:
Florian Schmaus 2020-05-22 09:20:02 +02:00
parent b3c57ef918
commit 962071762a

View file

@ -17,6 +17,7 @@
package org.jivesoftware.smack.packet; package org.jivesoftware.smack.packet;
import java.util.List;
import java.util.Locale; import java.util.Locale;
import javax.net.SocketFactory; import javax.net.SocketFactory;
@ -309,6 +310,16 @@ public final class Presence extends MessageOrPresence<PresenceBuilder>
if (type != Type.available) { if (type != Type.available) {
buf.attribute("type", type); buf.attribute("type", type);
} }
List<ExtensionElement> extensions = getExtensions();
if (status == null
&& priority == null
&& (mode == null || mode == Mode.available)
&& extensions.isEmpty()
&& getError() == null) {
return buf.closeEmptyElement();
}
buf.rightAngleBracket(); buf.rightAngleBracket();
buf.optElement("status", status); buf.optElement("status", status);
@ -317,7 +328,7 @@ public final class Presence extends MessageOrPresence<PresenceBuilder>
buf.element("show", mode); buf.element("show", mode);
} }
buf.append(getExtensions()); buf.append(extensions);
// Add the error sub-packet, if there is one. // Add the error sub-packet, if there is one.
appendErrorIfExists(buf); appendErrorIfExists(buf);