Only perform class and method lookup once
Summary: This caches the class and method id references between calls. The class lookup is done once per method still but I think that is ok for now as the code becomes somewhat cleaner and more self contained. Reviewed By: lucasr Differential Revision: D3661989 fbshipit-source-id: 68d4557364bb8957400aefb2603c2e46424ccec3
This commit is contained in:
committed by
Facebook Github Bot 9
parent
c74eae50ac
commit
f5caf93c6e
@@ -39,11 +39,17 @@ static void _jniPrint(void *context) {
|
|||||||
JNIEnv *env = NULL;
|
JNIEnv *env = NULL;
|
||||||
CSS_ASSERT((*jvm)->GetEnv(jvm, (void**) &env, JNI_VERSION) == JNI_OK, "Must have valid jni env");
|
CSS_ASSERT((*jvm)->GetEnv(jvm, (void**) &env, JNI_VERSION) == JNI_OK, "Must have valid jni env");
|
||||||
|
|
||||||
jclass cssNodeClass = (*env)->FindClass(env, "com/facebook/csslayout/CSSNodeJNI");
|
static jclass cssNodeClass = NULL;
|
||||||
CSS_ASSERT(cssNodeClass, "Could not find CSSNode class");
|
if (!cssNodeClass) {
|
||||||
|
cssNodeClass = (*env)->FindClass(env, "com/facebook/csslayout/CSSNodeJNI");
|
||||||
|
CSS_ASSERT(cssNodeClass, "Could not find CSSNode class");
|
||||||
|
}
|
||||||
|
|
||||||
jmethodID toStringID = (*env)->GetMethodID(env, cssNodeClass, "toString", "()Ljava/lang/String");
|
static jmethodID toStringID = NULL;
|
||||||
CSS_ASSERT(toStringID, "Could not find toString method");
|
if (!toStringID) {
|
||||||
|
toStringID = (*env)->GetMethodID(env, cssNodeClass, "toString", "()Ljava/lang/String");
|
||||||
|
CSS_ASSERT(toStringID, "Could not find toString method");
|
||||||
|
}
|
||||||
|
|
||||||
jstring javaString = (jstring) (*env)->CallObjectMethod(env, context, toStringID);
|
jstring javaString = (jstring) (*env)->CallObjectMethod(env, context, toStringID);
|
||||||
const char *nativeString = (*env)->GetStringUTFChars(env, javaString, 0);
|
const char *nativeString = (*env)->GetStringUTFChars(env, javaString, 0);
|
||||||
@@ -56,11 +62,17 @@ static CSSSize _jniMeasureFunc(void *context, float width, CSSMeasureMode widthM
|
|||||||
JNIEnv *env = NULL;
|
JNIEnv *env = NULL;
|
||||||
CSS_ASSERT((*jvm)->GetEnv(jvm, (void**) &env, JNI_VERSION) == JNI_OK, "Must have valid jni env");
|
CSS_ASSERT((*jvm)->GetEnv(jvm, (void**) &env, JNI_VERSION) == JNI_OK, "Must have valid jni env");
|
||||||
|
|
||||||
jclass cssNodeClass = (*env)->FindClass(env, "com/facebook/csslayout/CSSNodeJNI");
|
static jclass cssNodeClass = NULL;
|
||||||
CSS_ASSERT(cssNodeClass, "Could not find CSSNode class");
|
if (!cssNodeClass) {
|
||||||
|
cssNodeClass = (*env)->FindClass(env, "com/facebook/csslayout/CSSNodeJNI");
|
||||||
|
CSS_ASSERT(cssNodeClass, "Could not find CSSNode class");
|
||||||
|
}
|
||||||
|
|
||||||
jmethodID measureID = (*env)->GetMethodID(env, cssNodeClass, "measure", "(FIFI)J");
|
static jmethodID measureID = NULL;
|
||||||
CSS_ASSERT(measureID, "Could not find measure method");
|
if (!measureID) {
|
||||||
|
measureID = (*env)->GetMethodID(env, cssNodeClass, "measure", "(FIFI)J");
|
||||||
|
CSS_ASSERT(measureID, "Could not find measure method");
|
||||||
|
}
|
||||||
|
|
||||||
jlong measureResult = (*env)->CallLongMethod(env, context, measureID, width, widthMode, height, heightMode);
|
jlong measureResult = (*env)->CallLongMethod(env, context, measureID, width, widthMode, height, heightMode);
|
||||||
CSSSize size = {
|
CSSSize size = {
|
||||||
|
Reference in New Issue
Block a user