You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2015/03/11 22:35:39 UTC
svn commit: r1666017 -
/tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java
Author: markt
Date: Wed Mar 11 21:35:39 2015
New Revision: 1666017
URL: http://svn.apache.org/r1666017
Log:
Implement the merging.
I opted for certain clarity over the possible speed improvement of a more 'hands-on' implementation.
Modified:
tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java
Modified: tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java?rev=1666017&r1=1666016&r2=1666017&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java Wed Mar 11 21:35:39 2015
@@ -1928,10 +1928,22 @@ public class AprEndpoint extends Abstrac
private int mergeDescriptors(long[] desc, int startCount) {
if (OS.IS_BSD || OS.IS_MACOSX) {
- // TODO Need to actually implement merging of the descriptors here.
- // I'm currently thinking quicksort followed by running
- // through the sorted list to merge the events.
- return startCount;
+ /*
+ * Notes: Only the first startCount * 2 elements of the array
+ * are populated.
+ * The array is event, socket, event, socket etc.
+ */
+ HashMap<Long,Long> merged = new HashMap<>(startCount);
+ for (int n = 0; n < startCount; n++) {
+ merged.merge(Long.valueOf(desc[2*n+1]), Long.valueOf(desc[2*n]),
+ (v1, v2) -> Long.valueOf(v1.longValue() | v2.longValue()));
+ }
+ int i = 0;
+ for (Map.Entry<Long,Long> entry : merged.entrySet()) {
+ desc[i++] = entry.getValue().longValue();
+ desc[i++] = entry.getKey().longValue();
+ }
+ return merged.size();
} else {
// Other OS's do not (as far as it is known) return multiple
// entries for the same socket when the socket is registered for
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
Re: svn commit: r1666017 -
/tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java
Posted by Christopher Schultz <ch...@christopherschultz.net>.
Mark,
On 3/11/15 5:35 PM, markt@apache.org wrote:
> Author: markt
> Date: Wed Mar 11 21:35:39 2015
> New Revision: 1666017
>
> URL: http://svn.apache.org/r1666017
> Log:
> Implement the merging.
> I opted for certain clarity over the possible speed improvement of a more 'hands-on' implementation.
>
> Modified:
> tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java
>
> Modified: tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java
> URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java?rev=1666017&r1=1666016&r2=1666017&view=diff
> ==============================================================================
> --- tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java (original)
> +++ tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java Wed Mar 11 21:35:39 2015
> @@ -1928,10 +1928,22 @@ public class AprEndpoint extends Abstrac
>
> private int mergeDescriptors(long[] desc, int startCount) {
> if (OS.IS_BSD || OS.IS_MACOSX) {
You could avoid a check by installing a "DescriptorMerger" object that
is a no-op for non-BSD OSs if you wanted to avoid repeatedly-evaluated
conditional.
OS.IS_foo are all static final, though, so I expect the JIT to figure
that out eventually.
> - // TODO Need to actually implement merging of the descriptors here.
> - // I'm currently thinking quicksort followed by running
> - // through the sorted list to merge the events.
> - return startCount;
> + /*
> + * Notes: Only the first startCount * 2 elements of the array
> + * are populated.
> + * The array is event, socket, event, socket etc.
> + */
> + HashMap<Long,Long> merged = new HashMap<>(startCount);
> + for (int n = 0; n < startCount; n++) {
> + merged.merge(Long.valueOf(desc[2*n+1]), Long.valueOf(desc[2*n]),
I'm not sure what either javac or JIT will do with this, but you can
help it along a little bit:
for(...)
long l = n << 1;
merged.merge(Long.valueOf(l+1), Long.valueOf(l), ...)
-chris