Minor JNI performance improvement.
authorA. Unique TensorFlower <gardener@tensorflow.org>
Tue, 1 May 2018 22:01:22 +0000 (15:01 -0700)
committerTensorFlower Gardener <gardener@tensorflow.org>
Tue, 1 May 2018 22:06:01 +0000 (15:06 -0700)
PiperOrigin-RevId: 195002949

tensorflow/contrib/lite/java/src/main/native/tensor_jni.cc

index 17f4be0..005dca0 100644 (file)
@@ -238,10 +238,6 @@ Java_org_tensorflow_lite_Tensor_shape(JNIEnv* env, jclass clazz, jlong handle) {
   if (tensor == nullptr) return nullptr;
   int num_dims = tensor->dims->size;
   jintArray result = env->NewIntArray(num_dims);
-  jint* dims = env->GetIntArrayElements(result, nullptr);
-  for (int i = 0; i < num_dims; ++i) {
-    dims[i] = static_cast<jint>(tensor->dims->data[i]);
-  }
-  env->ReleaseIntArrayElements(result, dims, 0);
+  env->SetIntArrayRegion(result, 0, num_dims, tensor->dims->data);
   return result;
 }