You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@juneau.apache.org by ja...@apache.org on 2022/06/02 20:46:15 UTC

[juneau] branch master updated: Optimizations

This is an automated email from the ASF dual-hosted git repository.

jamesbognar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/juneau.git


The following commit(s) were added to refs/heads/master by this push:
     new bfd717683 Optimizations
bfd717683 is described below

commit bfd717683dad5fd8bca3dcfa862fbb677f392a56
Author: JamesBognar <ja...@salesforce.com>
AuthorDate: Thu Jun 2 16:40:55 2022 -0400

    Optimizations
---
 Jenkinsfile                                        |  2 +-
 .../apache/juneau/jena/RdfSerializerSession.java   |  4 +-
 .../apache/juneau/html/HtmlSerializerSession.java  | 10 +----
 .../apache/juneau/json/JsonSerializerSession.java  | 36 ++++++------------
 .../juneau/serializer/SerializerSession.java       | 44 ++++++++++++++++++++--
 .../apache/juneau/uon/UonSerializerSession.java    | 35 +++++++----------
 .../urlencoding/UrlEncodingSerializerSession.java  |  6 +--
 .../apache/juneau/xml/XmlSerializerSession.java    | 33 ++++++----------
 .../apache/juneau/rest/arg/RestOpContextArgs.java  |  1 +
 pom.xml                                            |  7 ++--
 10 files changed, 90 insertions(+), 88 deletions(-)

diff --git a/Jenkinsfile b/Jenkinsfile
index 582fd868e..851a8caff 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -25,7 +25,7 @@ timestamps {
 	
 				withMaven(jdk: 'JDK 1.8 (latest)', maven: 'Maven 3.2.5') { 
 					sh "echo hello"
-					sh "mvn clean install deploy javadoc:aggregate"
+					sh "mvn clean install deploy"
 				}
 				
 				junit '**/target/surefire-reports/*.xml' 
diff --git a/juneau-core/juneau-marshall-rdf/src/main/java/org/apache/juneau/jena/RdfSerializerSession.java b/juneau-core/juneau-marshall-rdf/src/main/java/org/apache/juneau/jena/RdfSerializerSession.java
index cdb0108e6..7a21c5057 100644
--- a/juneau-core/juneau-marshall-rdf/src/main/java/org/apache/juneau/jena/RdfSerializerSession.java
+++ b/juneau-core/juneau-marshall-rdf/src/main/java/org/apache/juneau/jena/RdfSerializerSession.java
@@ -294,8 +294,8 @@ public final class RdfSerializerSession extends WriterSerializerSession {
 
 		ClassMeta<?> cm = getClassMetaForObject(o);
 		if (isLooseCollections() && cm != null && cm.isCollectionOrArray()) {
-			Collection c = sort(cm.isCollection() ? (Collection)o : toList(cm.getInnerClass(), o));
-			c.forEach(x -> serializeAnything(x, false, object(), "root", null, null));
+			Collection c = cm.isCollection() ? (Collection)o : toList(cm.getInnerClass(), o);
+			forEachEntry(c, x -> serializeAnything(x, false, object(), "root", null, null));
 		} else {
 			RDFNode n = serializeAnything(o, false, getExpectedRootType(o), "root", null, null);
 			if (n.isLiteral()) {
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/html/HtmlSerializerSession.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/html/HtmlSerializerSession.java
index 6a34798c9..1330a1012 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/html/HtmlSerializerSession.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/html/HtmlSerializerSession.java
@@ -577,10 +577,7 @@ public class HtmlSerializerSession extends XmlSerializerSession {
 			out.ie(i+1).eTag("tr").nl(i+2);
 		}
 
-		if (isSortMaps())
-			m = sort(m);
-
-		((Set<Map.Entry>)m.entrySet()).forEach(x -> serializeMapEntry(out, x, keyType, valueType, i, ppMeta));
+		forEachEntry(m, x -> serializeMapEntry(out, x, keyType, valueType, i, ppMeta));
 
 		out.ie(i).eTag("table").nl(i);
 	}
@@ -925,10 +922,7 @@ public class HtmlSerializerSession extends XmlSerializerSession {
 				if (! canIgnoreValue(cm1, null, o)) {
 					if (! cm1.isInstance(o))
 						return null;
-					Map m = sort((Map)o);
-					m.forEach((k,v) -> {
-						if (! set.contains(k)) set.add(k);
-					});
+					forEachEntry((Map)o, x -> set.add(x.getKey()));
 				}
 			}
 			return set.toArray(new Object[set.size()]);
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/json/JsonSerializerSession.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/json/JsonSerializerSession.java
index c998457e1..8e6ed3750 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/json/JsonSerializerSession.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/json/JsonSerializerSession.java
@@ -343,26 +343,17 @@ public class JsonSerializerSession extends WriterSerializerSession {
 
 		ClassMeta<?> keyType = type.getKeyType(), valueType = type.getValueType();
 
-		m = sort(m);
-
 		int i = indent;
 		out.w('{');
 
-		Iterator mapEntries = m.entrySet().iterator();
-
-		while (mapEntries.hasNext()) {
-			Map.Entry e = (Map.Entry) mapEntries.next();
-			Object value = e.getValue();
-
-			Object key = generalize(e.getKey(), keyType);
-
+		Flag addComma = Flag.create();
+		forEachEntry(m, x -> {
+			addComma.ifSet(()->out.w(',').smi(i)).set();
+			Object value = x.getValue();
+			Object key = generalize(x.getKey(), keyType);
 			out.cr(i).attr(toString(key)).w(':').s(i);
-
 			serializeAnything(out, value, valueType, (key == null ? null : toString(key)), null);
-
-			if (mapEntries.hasNext())
-				out.w(',').smi(i);
-		}
+		});
 
 		out.cre(i-1).w('}');
 
@@ -406,17 +397,14 @@ public class JsonSerializerSession extends WriterSerializerSession {
 
 		ClassMeta<?> elementType = type.getElementType();
 
-		c = sort(c);
-
 		out.w('[');
-
-		for (Iterator i = c.iterator(); i.hasNext();) {
-			Object value = i.next();
+		Flag addComma = Flag.create();
+		forEachEntry(c, x -> {
+			addComma.ifSet(()->out.w(',').smi(indent)).set();
 			out.cr(indent);
-			serializeAnything(out, value, elementType, "<iterator>", null);
-			if (i.hasNext())
-				out.w(',').smi(indent);
-		}
+			serializeAnything(out, x, elementType, "<iterator>", null);
+		});
+
 		out.cre(indent-1).w(']');
 		return out;
 	}
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/serializer/SerializerSession.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/serializer/SerializerSession.java
index 02efe1620..8f392a140 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/serializer/SerializerSession.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/serializer/SerializerSession.java
@@ -601,11 +601,31 @@ public class SerializerSession extends BeanTraverseSession {
 	 * @return A new sorted {@link TreeMap}.
 	 */
 	public final <K,V> Map<K,V> sort(Map<K,V> m) {
-		if (isSortMaps() && isSortable(m == null ? null : m.keySet()))
+		if (m == null || m.isEmpty() || SortedMap.class.isInstance(m))
+			return m;
+		if (isSortMaps() && isSortable(m.keySet()))
 			return new TreeMap<>(m);
 		return m;
 	}
 
+	/**
+	 * Consumes each map entry in the map.
+	 *
+	 * @param <K> The key type.
+	 * @param <V> The value type.
+	 * @param m The map being consumed.
+	 * @param consumer The map entry consumer.
+	 */
+	@SuppressWarnings({ "unchecked", "rawtypes" })
+	public final <K,V> void forEachEntry(Map<K,V> m, Consumer<Map.Entry<K,V>> consumer) {
+		if (m == null || m.isEmpty())
+			return;
+		if (isSortMaps() && ! SortedMap.class.isInstance(m) && isSortable(m.keySet()))
+			((Map)m).entrySet().stream().sorted(Map.Entry.comparingByKey()).forEach(x -> consumer.accept((Map.Entry<K,V>) x));
+		else
+			m.entrySet().forEach(consumer);
+	}
+
 	/**
 	 * Sorts the specified collection if {@link SerializerSession#isSortCollections()} returns <jk>true</jk>.
 	 *
@@ -614,12 +634,29 @@ public class SerializerSession extends BeanTraverseSession {
 	 * @return A new sorted {@link TreeSet}.
 	 */
 	public final <E> Collection<E> sort(Collection<E> c) {
-		String TODO = "Inline?";
+		if (c == null || c.isEmpty() || SortedSet.class.isInstance(c))
+			return c;
 		if (isSortCollections() && isSortable(c))
 			return c.stream().sorted().collect(Collectors.toList());
 		return c;
 	}
 
+	/**
+	 * Consumes each entry in the list.
+	 *
+	 * @param <E> The element type.
+	 * @param c The collection being sorted.
+	 * @param consumer The entry consumer.
+	 */
+	public final <E> void forEachEntry(Collection<E> c, Consumer<E> consumer) {
+		if (c == null || c.isEmpty())
+			return;
+		if (isSortCollections() && ! SortedSet.class.isInstance(c) && isSortable(c))
+			c.stream().sorted().forEach(consumer);
+		else
+			c.forEach(consumer);
+	}
+
 	/**
 	 * Sorts the specified collection if {@link SerializerSession#isSortCollections()} returns <jk>true</jk>.
 	 *
@@ -628,7 +665,8 @@ public class SerializerSession extends BeanTraverseSession {
 	 * @return A new sorted {@link TreeSet}.
 	 */
 	public final <E> List<E> sort(List<E> c) {
-		String TODO = "Inline?";
+		if (c == null || c.isEmpty())
+			return c;
 		if (isSortCollections() && isSortable(c))
 			return c.stream().sorted().collect(Collectors.toList());
 		return c;
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/uon/UonSerializerSession.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/uon/UonSerializerSession.java
index 011ced23a..be1d9b9e0 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/uon/UonSerializerSession.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/uon/UonSerializerSession.java
@@ -363,27 +363,21 @@ public class UonSerializerSession extends WriterSerializerSession implements Htt
 	@SuppressWarnings({ "rawtypes", "unchecked" })
 	private SerializerWriter serializeMap(UonWriter out, Map m, ClassMeta<?> type) throws SerializeException {
 
-		m = sort(m);
-
 		ClassMeta<?> keyType = type.getKeyType(), valueType = type.getValueType();
 
 		if (! plainTextParams)
 			out.append('(');
 
-		Iterator mapEntries = m.entrySet().iterator();
-
-		while (mapEntries.hasNext()) {
-			Map.Entry e = (Map.Entry) mapEntries.next();
-			Object value = e.getValue();
-			Object key = generalize(e.getKey(), keyType);
+		Flag addComma = Flag.create();
+		forEachEntry(m, x -> {
+			addComma.ifSet(()->out.append(',')).set();
+			Object value = x.getValue();
+			Object key = generalize(x.getKey(), keyType);
 			out.cr(indent).appendObject(key, false).append('=');
 			serializeAnything(out, value, valueType, toString(key), null);
-			if (mapEntries.hasNext())
-				out.append(',');
-		}
+		});
 
-		if (m.size() > 0)
-			out.cre(indent-1);
+		addComma.ifSet(()->out.cre(indent-1));
 
 		if (! plainTextParams)
 			out.append(')');
@@ -434,20 +428,17 @@ public class UonSerializerSession extends WriterSerializerSession implements Htt
 
 		ClassMeta<?> elementType = type.getElementType();
 
-		c = sort(c);
-
 		if (! plainTextParams)
 			out.append('@').append('(');
 
-		for (Iterator i = c.iterator(); i.hasNext();) {
+		Flag addComma = Flag.create();
+		forEachEntry(c, x -> {
+			addComma.ifSet(()->out.append(',')).set();
 			out.cr(indent);
-			serializeAnything(out, i.next(), elementType, "<iterator>", null);
-			if (i.hasNext())
-				out.append(',');
-		}
+			serializeAnything(out, x, elementType, "<iterator>", null);
+		});
 
-		if (c.size() > 0)
-			out.cre(indent-1);
+		addComma.ifSet(()->out.cre(indent-1));
 		if (! plainTextParams)
 			out.append(')');
 
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/urlencoding/UrlEncodingSerializerSession.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/urlencoding/UrlEncodingSerializerSession.java
index cd1c89b4d..25a9b3dec 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/urlencoding/UrlEncodingSerializerSession.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/urlencoding/UrlEncodingSerializerSession.java
@@ -336,13 +336,11 @@ public class UrlEncodingSerializerSession extends UonSerializerSession {
 
 	private SerializerWriter serializeMap(UonWriter out, Map m, ClassMeta<?> type) throws SerializeException {
 
-		m = sort(m);
-
 		ClassMeta<?> keyType = type.getKeyType(), valueType = type.getValueType();
 
 		Flag addAmp = Flag.create();
 
-		for (Map.Entry e : (Set<Map.Entry>)m.entrySet()) {
+		forEachEntry(m, e -> {
 			Object key = generalize(e.getKey(), keyType);
 			Object value = e.getValue();
 
@@ -365,7 +363,7 @@ public class UrlEncodingSerializerSession extends UonSerializerSession {
 				out.appendObject(key, true).append('=');
 				super.serializeAnything(out, value, valueType, (key == null ? null : key.toString()), null);
 			}
-		}
+		});
 
 		return out;
 	}
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/xml/XmlSerializerSession.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/xml/XmlSerializerSession.java
index f3efdd499..a785546e0 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/xml/XmlSerializerSession.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/xml/XmlSerializerSession.java
@@ -674,14 +674,11 @@ public class XmlSerializerSession extends WriterSerializerSession {
 	private ContentResult serializeMap(XmlWriter out, Map m, ClassMeta<?> sType,
 			ClassMeta<?> eKeyType, ClassMeta<?> eValueType, boolean isMixed) throws SerializeException {
 
-		m = sort(m);
-
 		ClassMeta<?> keyType = eKeyType == null ? sType.getKeyType() : eKeyType;
 		ClassMeta<?> valueType = eValueType == null ? sType.getValueType() : eValueType;
 
-		boolean hasChildren = false;
-		for (Iterator i = m.entrySet().iterator(); i.hasNext();) {
-			Map.Entry e = (Map.Entry)i.next();
+		Flag hasChildren = Flag.create();
+		forEachEntry(m, e -> {
 
 			Object k = e.getKey();
 			if (k == null) {
@@ -694,13 +691,11 @@ public class XmlSerializerSession extends WriterSerializerSession {
 
 			Object value = e.getValue();
 
-			if (! hasChildren) {
-				hasChildren = true;
-				out.w('>').nlIf(! isMixed, indent);
-			}
+			hasChildren.ifNotSet(()->out.w('>').nlIf(! isMixed, indent)).set();
 			serializeAnything(out, value, valueType, toString(k), null, null, false, XmlFormat.DEFAULT, isMixed, false, null);
-		}
-		return hasChildren ? CR_ELEMENTS : CR_EMPTY;
+		});
+
+		return hasChildren.isSet() ? CR_ELEMENTS : CR_EMPTY;
 	}
 
 	private ContentResult serializeBeanMap(XmlWriter out, BeanMap<?> m,
@@ -849,23 +844,19 @@ public class XmlSerializerSession extends WriterSerializerSession {
 
 		Collection c = (sType.isCollection() ? (Collection)in : toList(sType.getInnerClass(), in));
 
-		c = sort(c);
-
 		String type2 = null;
 
-		String eName = type2;
-		Namespace eNs = null;
+		Value<String> eName = Value.of(type2);
+		Value<Namespace> eNs = Value.empty();
 
 		if (ppMeta != null) {
 			XmlBeanPropertyMeta bpXml = getXmlBeanPropertyMeta(ppMeta);
-			eName = bpXml.getChildName();
-			eNs = bpXml.getNamespace();
+			eName.set(bpXml.getChildName());
+			eNs.set(bpXml.getNamespace());
 		}
 
-		for (Iterator i = c.iterator(); i.hasNext();) {
-			Object value = i.next();
-			serializeAnything(out, value, eeType, null, eName, eNs, false, XmlFormat.DEFAULT, isMixed, false, null);
-		}
+		forEachEntry(c, x -> serializeAnything(out, x, eeType, null, eName.get(), eNs.get(), false, XmlFormat.DEFAULT, isMixed, false, null));
+
 		return out;
 	}
 
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/arg/RestOpContextArgs.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/arg/RestOpContextArgs.java
index 5d2aaff55..158649d7b 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/arg/RestOpContextArgs.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/arg/RestOpContextArgs.java
@@ -58,6 +58,7 @@ public class RestOpContextArgs extends SimpleRestOperationArg {
 	/**
 	 * Constructor.
 	 *
+	 * @param <T> The function return type.
 	 * @param function The function for finding the arg.
 	 */
 	protected <T> RestOpContextArgs(ThrowingFunction<RestOpContext,T> function) {
diff --git a/pom.xml b/pom.xml
index efcaa62d8..ef445293d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -52,6 +52,7 @@
 		<javax.inject.version>1</javax.inject.version>
 		<springboot.version>2.4.2</springboot.version>
 		<xml.apis.version>1.4.01</xml.apis.version>
+		<javadoc.executable></javadoc.executable>
 	</properties>
 
 	<dependencyManagement>
@@ -225,10 +226,10 @@
 						<sourcetab>3</sourcetab>
 						<notimestamp>true</notimestamp>
 						<verbose>true</verbose>
-						<additionalparam>&#45;&#45;allow-script-in-comments</additionalparam>
 						<additionalJOptions>
 							<additionalJOption>-J-DjuneauVersion=${juneauVersion}</additionalJOption>
 							<additionalJOption>-J-DjuneauVersionNext=${juneauVersionNext}</additionalJOption>
+							<additionalJOption>--allow-script-in-comments</additionalJOption>
 						</additionalJOptions>
 						<show>protected</show>
 						<windowtitle>Apache Juneau ${project.version}</windowtitle>
@@ -251,7 +252,7 @@
 						</links>
 						<docfilessubdirs>true</docfilessubdirs>
 						<javadocDirectory>${basedir}/juneau-doc/src/main/javadoc</javadocDirectory>
-						<javadocExecutable>/Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk/Contents/Home/bin/javadoc</javadocExecutable>
+						<javadocExecutable>${javadoc.executable}</javadocExecutable>
 						<taglets>
 							<taglet>
 								<tagletClass>org.apache.juneau.doc.internal.DelTag</tagletClass>
@@ -275,7 +276,7 @@
 								<tagletClass>org.apache.juneau.doc.internal.ReviewedTag</tagletClass>
 							</taglet>
 						</taglets>
-						<tagletpath>${basedir}/juneau-doc/tools.jar:${basedir}/juneau-doc/juneau-doc.jar</tagletpath>
+						<tagletpath>${basedir}/juneau-doc/juneau-doc.jar</tagletpath>
 					</configuration>
 					<executions>
 						<execution>