From 962071762a99f73ed4ad43eab0fbdbed31aa90fe Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Fri, 22 May 2020 09:20:02 +0200 Subject: [PATCH] [core] Optimize Presence.toXML() for empty element --- .../org/jivesoftware/smack/packet/Presence.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/smack-core/src/main/java/org/jivesoftware/smack/packet/Presence.java b/smack-core/src/main/java/org/jivesoftware/smack/packet/Presence.java index 9a1d1a43d..7d37ed50c 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/packet/Presence.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/packet/Presence.java @@ -17,6 +17,7 @@ package org.jivesoftware.smack.packet; +import java.util.List; import java.util.Locale; import javax.net.SocketFactory; @@ -309,6 +310,16 @@ public final class Presence extends MessageOrPresence if (type != Type.available) { buf.attribute("type", type); } + + List extensions = getExtensions(); + if (status == null + && priority == null + && (mode == null || mode == Mode.available) + && extensions.isEmpty() + && getError() == null) { + return buf.closeEmptyElement(); + } + buf.rightAngleBracket(); buf.optElement("status", status); @@ -317,7 +328,7 @@ public final class Presence extends MessageOrPresence buf.element("show", mode); } - buf.append(getExtensions()); + buf.append(extensions); // Add the error sub-packet, if there is one. appendErrorIfExists(buf);