diff options
author | Android (Google) Code Review <android-gerrit@google.com> | 2009-09-09 16:54:08 -0400 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2009-09-09 16:54:08 -0400 |
commit | 91e2974c5b1f3b938a4f1f1c57447d01973ad0ba (patch) | |
tree | 0043466ae1c8ea2f5510c9b9719941f2cc82b49c /icu | |
parent | 6fc3381cd19a5b2909910432b73db9b2a09ec2b9 (diff) | |
parent | d22b51d937a42b52497eb9a53d41c55b23003ee5 (diff) | |
download | libcore-91e2974c5b1f3b938a4f1f1c57447d01973ad0ba.zip libcore-91e2974c5b1f3b938a4f1f1c57447d01973ad0ba.tar.gz libcore-91e2974c5b1f3b938a4f1f1c57447d01973ad0ba.tar.bz2 |
Merge change 24402
* changes:
Use GetByteArrayRegion instead of GetByteArrayElements.
Diffstat (limited to 'icu')
-rw-r--r-- | icu/src/main/native/BidiWrapperInterface.c | 44 |
1 files changed, 17 insertions, 27 deletions
diff --git a/icu/src/main/native/BidiWrapperInterface.c b/icu/src/main/native/BidiWrapperInterface.c index 2c6b3cd..55be7a0 100644 --- a/icu/src/main/native/BidiWrapperInterface.c +++ b/icu/src/main/native/BidiWrapperInterface.c @@ -43,44 +43,34 @@ JNIEXPORT void JNICALL Java_org_apache_harmony_text_BidiWrapper_ubidi_1close ubidi_close ((*data).pBiDi); - if ((*data).embeddingLevels != NULL) - free((*data).embeddingLevels); - free(data); + free((*data).embeddingLevels); + free(data); } JNIEXPORT void JNICALL Java_org_apache_harmony_text_BidiWrapper_ubidi_1setPara (JNIEnv * env, jclass clazz, jlong pBiDi, jcharArray text, jint length, - jbyte paraLevel, jbyteArray embeddingLevels) + jbyte paraLevel, jbyteArray newEmbeddingLevels) { - UErrorCode err = 0; - jchar *_text = NULL; BiDiData *data = (BiDiData *)pBiDi; - /* Remembering old embedding levels */ - void *embLvls = (*data).embeddingLevels; - - _text = (*env)->GetCharArrayElements (env, text, NULL); - - if (embeddingLevels != NULL) - { - jbyte *el = (*env)->GetByteArrayElements (env, embeddingLevels, NULL); - (*data).embeddingLevels = malloc(length); - memcpy(((*data).embeddingLevels), el, length); - (*env)->ReleaseByteArrayElements (env, embeddingLevels, el, 0); - } else - { - (*data).embeddingLevels = NULL; - } + void *oldEmbeddingLevels = (*data).embeddingLevels; + + // Copy the new embedding levels from the Java heap to the native heap. + if (newEmbeddingLevels != NULL) { + (*data).embeddingLevels = malloc(length); + (*env)->GetByteArrayRegion(env, newEmbeddingLevels, 0, length, + (*data).embeddingLevels); + } else { + (*data).embeddingLevels = NULL; + } + UErrorCode err = 0; + jchar* _text = (*env)->GetCharArrayElements(env, text, NULL); ubidi_setPara ((*data).pBiDi, _text, length, paraLevel, ((*data).embeddingLevels), &err); + (*env)->ReleaseCharArrayElements (env, text, _text, 0); check_fail (env, err); - /* Freeing old embedding levels */ - if (embLvls != NULL) { - free(embLvls); - } - - (*env)->ReleaseCharArrayElements (env, text, _text, 0); + free(oldEmbeddingLevels); } JNIEXPORT jlong JNICALL Java_org_apache_harmony_text_BidiWrapper_ubidi_1setLine |