diff options
author | Elliott Hughes <enh@google.com> | 2009-09-09 12:02:08 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2009-09-09 12:02:08 -0700 |
commit | d22b51d937a42b52497eb9a53d41c55b23003ee5 (patch) | |
tree | 8c09f56ac0e67cb97f351aaf81d7ab336ff66c58 /icu/src/main/native | |
parent | 1c4559adb84387b1b8bcee40c7e0bff0ecdd1334 (diff) | |
download | libcore-d22b51d937a42b52497eb9a53d41c55b23003ee5.zip libcore-d22b51d937a42b52497eb9a53d41c55b23003ee5.tar.gz libcore-d22b51d937a42b52497eb9a53d41c55b23003ee5.tar.bz2 |
Use GetByteArrayRegion instead of GetByteArrayElements.
I've also cleaned up the two calls to free(3) in ubidi_close; the former had
an unnecessary NULL check, and the latter was indented as if it belonged to the
if (but didn't).
Tested on sapphire-eng.
Diffstat (limited to 'icu/src/main/native')
-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 |