subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hwri...@apache.org
Subject svn commit: r925517 - in /subversion/trunk/subversion/bindings/javahl/native: EnumMapper.cpp EnumMapper.h
Date Sat, 20 Mar 2010 01:41:38 GMT
Author: hwright
Date: Sat Mar 20 01:41:37 2010
New Revision: 925517

URL: http://svn.apache.org/viewvc?rev=925517&view=rev
Log:
JavaHL: (Ab)use our knowledge of the Java and C enum values to be much more
efficient about converting between the two.

[ in subversion/bindings/javahl/ ]
* native/EnumMapper.h
  (mapEnum): New version of this function.
 
* native/EnumMapper.cpp
  (mapSummarizeKind): Reimplment using the new mapEnum() method.
  (mapEnum): New.

Modified:
    subversion/trunk/subversion/bindings/javahl/native/EnumMapper.cpp
    subversion/trunk/subversion/bindings/javahl/native/EnumMapper.h

Modified: subversion/trunk/subversion/bindings/javahl/native/EnumMapper.cpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/EnumMapper.cpp?rev=925517&r1=925516&r2=925517&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/EnumMapper.cpp (original)
+++ subversion/trunk/subversion/bindings/javahl/native/EnumMapper.cpp Sat Mar 20 01:41:37
2010
@@ -552,21 +552,43 @@ svn_opt_revision_kind EnumMapper::toRevi
 
 jobject EnumMapper::mapSummarizeKind(svn_client_diff_summarize_kind_t sKind)
 {
-  switch (sKind)
-    {
-    default:
-    case svn_client_diff_summarize_kind_normal:
-      return mapEnum(JAVA_PACKAGE"/DiffSummary$DiffKind", "normal");
-
-    case svn_client_diff_summarize_kind_added:
-      return mapEnum(JAVA_PACKAGE"/DiffSummary$DiffKind", "added");
-
-    case svn_client_diff_summarize_kind_modified:
-      return mapEnum(JAVA_PACKAGE"/DiffSummary$DiffKind", "modified");
-
-    case svn_client_diff_summarize_kind_deleted:
-      return mapEnum(JAVA_PACKAGE"/DiffSummary$DiffKind", "deleted");
-    }
+  // We're assuming a value value for the C enum above
+  return mapEnum(JAVA_PACKAGE"/DiffSummary$DiffKind", (int) sKind);
+}
+
+jobject EnumMapper::mapEnum(const char *clazzName, int index)
+{
+  // The fact that we can even do this depends upon a couple of assumptions,
+  // mainly some knowledge about the orderin of the various constants in
+  // both the C and Java enums.  Should those values ever change,
+  // the World Will End.
+
+  std::string methodSig("()[L");
+  methodSig.append(clazzName);
+  methodSig.append(";");
+
+  JNIEnv *env = JNIUtil::getEnv();
+
+  // Create a local frame for our references
+  env->PushLocalFrame(LOCAL_FRAME_SIZE);
+  if (JNIUtil::isJavaExceptionThrown())
+    return NULL;
+
+  jclass clazz = env->FindClass(clazzName);
+  if (JNIUtil::isJavaExceptionThrown())
+    POP_AND_RETURN_NULL;
+
+  jmethodID mid = env->GetStaticMethodID(clazz, "values", methodSig.c_str());
+  if (JNIUtil::isJavaExceptionThrown())
+    POP_AND_RETURN_NULL;
+
+  jobjectArray jvalues = (jobjectArray) env->CallStaticObjectMethod(clazz, mid);
+  if (JNIUtil::isJavaExceptionThrown())
+    POP_AND_RETURN_NULL;
+
+  jobject jthing = env->GetObjectArrayElement(jvalues, index);
+
+  return env->PopLocalFrame(jthing);
 }
 
 jobject EnumMapper::mapEnum(const char *clazzName, const char *name)

Modified: subversion/trunk/subversion/bindings/javahl/native/EnumMapper.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/EnumMapper.h?rev=925517&r1=925516&r2=925517&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/EnumMapper.h (original)
+++ subversion/trunk/subversion/bindings/javahl/native/EnumMapper.h Sat Mar 20 01:41:37 2010
@@ -63,6 +63,7 @@ class EnumMapper
   static jobject mapSummarizeKind(svn_client_diff_summarize_kind_t);
  private:
   static jobject mapEnum(const char *clazzName, const char *name);
+  static jobject mapEnum(const char *clazzName, int offset);
   static jstring getName(const char *clazzName, jobject jenum);
 };
 



Mime
View raw message