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

Side by Side Diff: base/android/jni_array.cc

Issue 1314753002: [Android] Adding JavaLongArrayToInt64Vector method (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removing reinterpret_cast Created 5 years, 4 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 unified diff | Download patch
« no previous file with comments | « base/android/jni_array.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/android/jni_array.h" 5 #include "base/android/jni_array.h"
6 6
7 #include "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h" 8 #include "base/android/jni_string.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 10
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 DCHECK(out); 178 DCHECK(out);
179 size_t len = SafeGetArrayLength(env, int_array); 179 size_t len = SafeGetArrayLength(env, int_array);
180 out->resize(len); 180 out->resize(len);
181 if (!len) 181 if (!len)
182 return; 182 return;
183 // TODO(jdduke): Use |out->data()| for pointer access after switch to libc++, 183 // TODO(jdduke): Use |out->data()| for pointer access after switch to libc++,
184 // both here and in the other conversion routines. See crbug.com/427718. 184 // both here and in the other conversion routines. See crbug.com/427718.
185 env->GetIntArrayRegion(int_array, 0, len, &(*out)[0]); 185 env->GetIntArrayRegion(int_array, 0, len, &(*out)[0]);
186 } 186 }
187 187
188 void JavaLongArrayToInt64Vector(JNIEnv* env,
189 jlongArray long_array,
190 std::vector<int64>* out) {
191 DCHECK(out);
192 std::vector<jlong> temp;
193 JavaLongArrayToLongVector(env, long_array, &temp);
194 out->resize(0);
195 out->insert(out->begin(), temp.begin(), temp.end());
196 }
197
188 void JavaLongArrayToLongVector(JNIEnv* env, 198 void JavaLongArrayToLongVector(JNIEnv* env,
189 jlongArray long_array, 199 jlongArray long_array,
190 std::vector<jlong>* out) { 200 std::vector<jlong>* out) {
191 DCHECK(out); 201 DCHECK(out);
192 size_t len = SafeGetArrayLength(env, long_array); 202 size_t len = SafeGetArrayLength(env, long_array);
193 out->resize(len); 203 out->resize(len);
194 if (!len) 204 if (!len)
195 return; 205 return;
196 env->GetLongArrayRegion(long_array, 0, len, &(*out)[0]); 206 env->GetLongArrayRegion(long_array, 0, len, &(*out)[0]);
197 } 207 }
(...skipping 22 matching lines...) Expand all
220 env->GetObjectArrayElement(array, i))); 230 env->GetObjectArrayElement(array, i)));
221 jsize bytes_len = env->GetArrayLength(bytes_array.obj()); 231 jsize bytes_len = env->GetArrayLength(bytes_array.obj());
222 jbyte* bytes = env->GetByteArrayElements(bytes_array.obj(), NULL); 232 jbyte* bytes = env->GetByteArrayElements(bytes_array.obj(), NULL);
223 (*out)[i].assign(reinterpret_cast<const char*>(bytes), bytes_len); 233 (*out)[i].assign(reinterpret_cast<const char*>(bytes), bytes_len);
224 env->ReleaseByteArrayElements(bytes_array.obj(), bytes, JNI_ABORT); 234 env->ReleaseByteArrayElements(bytes_array.obj(), bytes, JNI_ABORT);
225 } 235 }
226 } 236 }
227 237
228 } // namespace android 238 } // namespace android
229 } // namespace base 239 } // namespace base
OLDNEW
« no previous file with comments | « base/android/jni_array.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698