You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by hi...@apache.org on 2008/02/05 15:08:41 UTC
svn commit: r618657 -
/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/OSNetworkSystemLinux.c
Author: hindessm
Date: Tue Feb 5 06:08:40 2008
New Revision: 618657
URL: http://svn.apache.org/viewvc?rev=618657&view=rev
Log:
Avoid array copy if there are no changes to the original (zeroed) outFlags
array.
Modified:
harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/OSNetworkSystemLinux.c
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/OSNetworkSystemLinux.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/OSNetworkSystemLinux.c?rev=618657&r1=618656&r2=618657&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/OSNetworkSystemLinux.c (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/OSNetworkSystemLinux.c Tue Feb 5 06:08:40 2008
@@ -241,6 +241,7 @@
* Class: org_apache_harmony_luni_platform_OSNetworkSystem
* Method: selectImpl
* Signature: ([Ljava/io/FileDescriptor;[Ljava/io/FileDescriptor;II[IJ)I
+ * Assumption: outFlags is zeroed
*/
JNIEXPORT jint JNICALL Java_org_apache_harmony_luni_platform_OSNetworkSystem_selectImpl
(JNIEnv * env, jclass thisClz, jobjectArray readFDArray, jobjectArray writeFDArray,
@@ -287,24 +288,23 @@
result = poll(my_pollfds, n_pollfds, timeout);
if (result > 0) {
+ int changed = 0; /* Record if we actually change the IntArray */
/* output result to int array */
- flagArray = (*env)->GetIntArrayElements(env,outFlags, &isCopy);
+ flagArray = (*env)->GetIntArrayElements(env, outFlags, &isCopy);
for (val=0; val<countReadC; val++) {
if (my_pollfds[val].revents & (POLLIN | POLLPRI)) {
flagArray[val] = SOCKET_OP_READ;
- } else {
- flagArray[val] = SOCKET_OP_NONE;
+ changed=1;
}
}
for (val=0; val<countWriteC; val++) {
if (my_pollfds[val+countReadC].revents & POLLOUT) {
flagArray[val+countReadC] = SOCKET_OP_WRITE;
- } else {
- flagArray[val+countReadC] = SOCKET_OP_NONE;
+ changed=1;
}
}
- (*env)->ReleaseIntArrayElements(env, outFlags, flagArray, 0);
+ (*env)->ReleaseIntArrayElements(env, outFlags, flagArray, changed ? 0 : JNI_ABORT);
}
hymem_free_memory(my_pollfds);