Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2742)

Unified Diff: base/android/jni_array.cc

Issue 138653002: Eliminate potential copy in Java array conversions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/android/jni_array.cc
diff --git a/base/android/jni_array.cc b/base/android/jni_array.cc
index 0b2b67f8f2290828dc1123fd4b3abf881437798d..96c5980362d2affde03b53425d47089e24154939 100644
--- a/base/android/jni_array.cc
+++ b/base/android/jni_array.cc
@@ -17,9 +17,8 @@ ScopedJavaLocalRef<jbyteArray> ToJavaByteArray(
CheckException(env);
DCHECK(byte_array);
- jbyte* elements = env->GetByteArrayElements(byte_array, NULL);
- memcpy(elements, bytes, len);
- env->ReleaseByteArrayElements(byte_array, elements, 0);
+ env->SetByteArrayRegion(
+ byte_array, 0, len, reinterpret_cast<const jbyte*>(bytes));
CheckException(env);
return ScopedJavaLocalRef<jbyteArray>(env, byte_array);
@@ -31,9 +30,8 @@ ScopedJavaLocalRef<jintArray> ToJavaIntArray(
CheckException(env);
DCHECK(int_array);
- jint* elements = env->GetIntArrayElements(int_array, NULL);
- memcpy(elements, ints, len * sizeof(*ints));
- env->ReleaseIntArrayElements(int_array, elements, 0);
+ env->SetIntArrayRegion(
+ int_array, 0, len, reinterpret_cast<const jint*>(ints));
CheckException(env);
return ScopedJavaLocalRef<jintArray>(env, int_array);
@@ -50,9 +48,8 @@ ScopedJavaLocalRef<jlongArray> ToJavaLongArray(
CheckException(env);
DCHECK(long_array);
- jlong* elements = env->GetLongArrayElements(long_array, NULL);
- memcpy(elements, longs, len * sizeof(*longs));
- env->ReleaseLongArrayElements(long_array, elements, 0);
+ env->SetLongArrayRegion(
+ long_array, 0, len, reinterpret_cast<const jlong*>(longs));
CheckException(env);
return ScopedJavaLocalRef<jlongArray>(env, long_array);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698