diff options
author | Elliott Hughes <enh@google.com> | 2010-06-16 16:32:18 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2010-06-16 16:32:18 -0700 |
commit | a9f5c16a864ff63ba63f810410f8a27c086d5d52 (patch) | |
tree | 2dd4b885c23ada270ca59bff053ffc2f16577eab /luni/src/main/native/BidiWrapper.cpp | |
parent | d93bf0f076628f52c56610853435f04ce9983a15 (diff) | |
download | libcore-a9f5c16a864ff63ba63f810410f8a27c086d5d52.zip libcore-a9f5c16a864ff63ba63f810410f8a27c086d5d52.tar.gz libcore-a9f5c16a864ff63ba63f810410f8a27c086d5d52.tar.bz2 |
Remove dynamic calls to FindClass.
Initially, I was just fixing a threading bug in NativeDecimalFormat.cpp where
we were bypassing GCC's built-in static initializer thread safety. This led me
to the question of how expensive FindClass is, which led me to creating a new
canonical cache of jclasses.
Here's the motivating benchmark, showing the cost of calling an empty regular
(non-native) method, an empty native method, a native method that calls
FindClass, a native method that calls FindClass and GetFieldID, and a native
method that calls FindClass and GetMethodID:
benchmark ns logarithmic runtime
NoArgsRegular 74 ||||||||||||||
NoArgsNative 428 XX|||||||||||||||||||
FindClass 3064 XXXXXXXXXXXXXXXX|||||||||||
FindClassGetField 3654 XXXXXXXXXXXXXXXXXXX|||||||||
FindClassGetMethod 5634 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Change-Id: I41ab2b347895f043a7e21d8fa19e4541e198c3fc
Diffstat (limited to 'luni/src/main/native/BidiWrapper.cpp')
-rw-r--r-- | luni/src/main/native/BidiWrapper.cpp | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/luni/src/main/native/BidiWrapper.cpp b/luni/src/main/native/BidiWrapper.cpp index 59dcfaa..f703586 100644 --- a/luni/src/main/native/BidiWrapper.cpp +++ b/luni/src/main/native/BidiWrapper.cpp @@ -16,11 +16,13 @@ */ #define LOG_TAG "BidiWrapper" -#include <JNIHelp.h> #include "ErrorCode.h" +#include "JNIHelp.h" +#include "JniConstants.h" #include "ScopedPrimitiveArray.h" #include "UniquePtr.h" #include "unicode/ubidi.h" + #include <stdlib.h> #include <string.h> @@ -135,15 +137,14 @@ static jobjectArray BidiWrapper_ubidi_getRuns(JNIEnv* env, jclass, jlong ptr) { if (icu4jni_error(env, err)) { return NULL; } - jclass bidiRunClass = env->FindClass("org/apache/harmony/text/BidiRun"); - jmethodID bidiRunConstructor = env->GetMethodID(bidiRunClass, "<init>", "(III)V"); - jobjectArray runs = env->NewObjectArray(runCount, bidiRunClass, NULL); + jmethodID bidiRunConstructor = env->GetMethodID(JniConstants::bidiRunClass, "<init>", "(III)V"); + jobjectArray runs = env->NewObjectArray(runCount, JniConstants::bidiRunClass, NULL); UBiDiLevel level = 0; int start = 0; int limit = 0; for (int i = 0; i < runCount; ++i) { ubidi_getLogicalRun(ubidi, start, &limit, &level); - jobject run = env->NewObject(bidiRunClass, bidiRunConstructor, start, limit, level); + jobject run = env->NewObject(JniConstants::bidiRunClass, bidiRunConstructor, start, limit, level); env->SetObjectArrayElement(runs, i, run); start = limit; } |