subversion-commits mailing list archives

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

URL: http://svn.apache.org/viewvc?rev=925663&view=rev
Log:
JavaHL: Use a much more efficient method of converting from the Java enums to
the C equivalents (via the Java ordinal() method).

[ in subversion/bindings/javahl/ ]
* native/EnumMapper.h
  (getName): Remove.
  (getOrdinal): New.

* native/EnumMapper.cpp
  (toDepth, toConflictChoice, toRevisionKind): Use the getOrdinal() method to
    map to the C enum value.
  (getName): Remove.
  (getOrdinal): 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=925663&r1=925662&r2=925663&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/EnumMapper.cpp (original)
+++ subversion/trunk/subversion/bindings/javahl/native/EnumMapper.cpp Sat Mar 20 19:35:35
2010
@@ -157,27 +157,8 @@ jobject EnumMapper::mapConflictReason(sv
 
 svn_depth_t EnumMapper::toDepth(jobject jdepth)
 {
-  JNIEnv *env = JNIUtil::getEnv();
-
-  jstring jname = getName(JAVA_PACKAGE"/Depth", jdepth);
-  if (JNIUtil::isJavaExceptionThrown())
-    return (svn_depth_t)0;
-
-  JNIStringHolder str(jname);
-  std::string name((const char *)str);
-
-  if (name == "infinity")
-    return svn_depth_infinity;
-  else if (name == "immediates")
-    return svn_depth_immediates;
-  else if (name == "files")
-    return svn_depth_files;
-  else if (name == "empty")
-    return svn_depth_empty;
-  else if (name == "exclude")
-    return svn_depth_exclude;
-  else
-    return svn_depth_unknown;
+  // The offset for depths is -2
+  return (svn_depth_t) (getOrdinal(JAVA_PACKAGE"/Depth", jdepth) - 2);
 }
 
 jobject EnumMapper::mapDepth(svn_depth_t depth)
@@ -211,58 +192,14 @@ jobject EnumMapper::mapTristate(svn_tris
 
 svn_wc_conflict_choice_t EnumMapper::toConflictChoice(jobject jchoice)
 {
-  JNIEnv *env = JNIUtil::getEnv();
-
-  jstring jname = getName(JAVA_PACKAGE"/ConflictResult$Choice", jchoice);
-  if (JNIUtil::isJavaExceptionThrown())
-    return svn_wc_conflict_choose_postpone;
-
-  JNIStringHolder str(jname);
-  std::string name((const char *)str);
-
-  if (name == "chooseBase")
-    return svn_wc_conflict_choose_base;
-  else if (name == "chooseTheirsFull")
-    return svn_wc_conflict_choose_theirs_full;
-  else if (name == "chooseMineFull")
-    return svn_wc_conflict_choose_mine_full;
-  else if (name == "chooseTheirsConflict")
-    return svn_wc_conflict_choose_theirs_conflict;
-  else if (name == "chooseMineConflict")
-    return svn_wc_conflict_choose_mine_conflict;
-  else if (name == "chooseMerged")
-    return svn_wc_conflict_choose_merged;
-  else
-    return svn_wc_conflict_choose_postpone;
+  return (svn_wc_conflict_choice_t) getOrdinal(
+                        JAVA_PACKAGE"/ConflictResult$Choice", jchoice);
 }
 
 svn_opt_revision_kind EnumMapper::toRevisionKind(jobject jkind)
 {
-  JNIEnv *env = JNIUtil::getEnv();
-
-  jstring jname = getName(JAVA_PACKAGE"/Revision$Kind", jkind);
-  if (JNIUtil::isJavaExceptionThrown())
-    return svn_opt_revision_unspecified;
-
-  JNIStringHolder str(jname);
-  std::string name((const char *)str);
-
-  if (name == "number")
-    return svn_opt_revision_number;
-  else if (name == "date")
-    return svn_opt_revision_date;
-  else if (name == "committed")
-    return svn_opt_revision_committed;
-  else if (name == "previous")
-    return svn_opt_revision_previous;
-  else if (name == "base")
-    return svn_opt_revision_base;
-  else if (name == "working")
-    return svn_opt_revision_working;
-  else if (name == "head")
-    return svn_opt_revision_head;
-  else
-    return svn_opt_revision_unspecified;
+  return (svn_opt_revision_kind) getOrdinal(JAVA_PACKAGE"/Revision$Kind",
+                                            jkind);
 }
 
 jobject EnumMapper::mapSummarizeKind(svn_client_diff_summarize_kind_t sKind)
@@ -308,26 +245,26 @@ jobject EnumMapper::mapEnum(const char *
   return env->PopLocalFrame(jthing);
 }
 
-jstring EnumMapper::getName(const char *clazzName, jobject jenum)
+int EnumMapper::getOrdinal(const char *clazzName, jobject jenum)
 {
   JNIEnv *env = JNIUtil::getEnv();
 
   // Create a local frame for our references
   env->PushLocalFrame(LOCAL_FRAME_SIZE);
   if (JNIUtil::isJavaExceptionThrown())
-    return NULL;
+    return -1;
 
   jclass clazz = env->FindClass(clazzName);
   if (JNIUtil::isJavaExceptionThrown())
-    POP_AND_RETURN_NULL;
+    POP_AND_RETURN(-1);
 
-  jmethodID mid = env->GetMethodID(clazz, "name", "()Ljava/lang/String;");
+  jmethodID mid = env->GetMethodID(clazz, "ordinal", "()I");
   if (JNIUtil::isJavaExceptionThrown())
-    POP_AND_RETURN_NULL;
+    POP_AND_RETURN(-1);
 
-  jstring jname = (jstring) env->CallObjectMethod(jenum, mid);
+  jint jorder = env->CallIntMethod(jenum, mid);
   if (JNIUtil::isJavaExceptionThrown())
-    POP_AND_RETURN_NULL;
+    POP_AND_RETURN(-1);
 
-  return (jstring) env->PopLocalFrame(jname);
+  return (int) jorder;
 }

Modified: subversion/trunk/subversion/bindings/javahl/native/EnumMapper.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/EnumMapper.h?rev=925663&r1=925662&r2=925663&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/EnumMapper.h (original)
+++ subversion/trunk/subversion/bindings/javahl/native/EnumMapper.h Sat Mar 20 19:35:35 2010
@@ -63,7 +63,7 @@ class EnumMapper
   static jobject mapSummarizeKind(svn_client_diff_summarize_kind_t);
  private:
   static jobject mapEnum(const char *clazzName, int offset);
-  static jstring getName(const char *clazzName, jobject jenum);
+  static int getOrdinal(const char *clazzName, jobject jenum);
 };
 
 #endif  // ENUM_MAPPER_H



Mime
View raw message