You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by hw...@apache.org on 2010/03/03 16:36:10 UTC
svn commit: r918516 - in
/subversion/trunk/subversion/bindings/javahl/native: CreateJ.cpp CreateJ.h
SVNAdmin.cpp
Author: hwright
Date: Wed Mar 3 15:36:10 2010
New Revision: 918516
URL: http://svn.apache.org/viewvc?rev=918516&view=rev
Log:
Simplify the creating of Sets in JavaHL.
* subversion/bindings/javahl/native/CreateJ.cpp
(StringSet): Use the new helper function.
(Set): New.
* subversion/bindings/javahl/native/SVNAdmin.cpp
(lsLocks): Use the new helper function.
* subversion/bindings/javahl/native/CreateJ.h
(Set): New.
Modified:
subversion/trunk/subversion/bindings/javahl/native/CreateJ.cpp
subversion/trunk/subversion/bindings/javahl/native/CreateJ.h
subversion/trunk/subversion/bindings/javahl/native/SVNAdmin.cpp
Modified: subversion/trunk/subversion/bindings/javahl/native/CreateJ.cpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/CreateJ.cpp?rev=918516&r1=918515&r2=918516&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/CreateJ.cpp (original)
+++ subversion/trunk/subversion/bindings/javahl/native/CreateJ.cpp Wed Mar 3 15:36:10 2010
@@ -390,29 +390,7 @@
CreateJ::StringSet(apr_array_header_t *strings)
{
JNIEnv *env = JNIUtil::getEnv();
- jclass clazz = env->FindClass("java/util/HashSet");
- if (JNIUtil::isJavaExceptionThrown())
- return NULL;
-
- static jmethodID init_mid = 0;
- if (init_mid == 0)
- {
- init_mid = env->GetMethodID(clazz, "<init>", "()V");
- if (JNIUtil::isJavaExceptionThrown())
- return NULL;
- }
-
- static jmethodID add_mid = 0;
- if (add_mid == 0)
- {
- add_mid = env->GetMethodID(clazz, "add", "(Ljava/lang/Object;)Z");
- if (JNIUtil::isJavaExceptionThrown())
- return NULL;
- }
-
- jobject set = env->NewObject(clazz, init_mid);
- if (JNIUtil::isJavaExceptionThrown())
- return NULL;
+ std::vector<jobject> jstrs;
for (int i = 0; i < strings->nelts; ++i)
{
@@ -420,21 +398,11 @@
jstring jstr = JNIUtil::makeJString(str);
if (JNIUtil::isJavaExceptionThrown())
return NULL;
-
- env->CallObjectMethod(set, add_mid, jstr);
- if (JNIUtil::isJavaExceptionThrown())
- return NULL;
-
- env->DeleteLocalRef(jstr);
- if (JNIUtil::isJavaExceptionThrown())
- return NULL;
+
+ jstrs.push_back(jstr);
}
- env->DeleteLocalRef(clazz);
- if (JNIUtil::isJavaExceptionThrown())
- return NULL;
-
- return set;
+ return CreateJ::Set(jstrs);
}
jobject CreateJ::PropertyMap(apr_hash_t *prop_hash, apr_pool_t *pool)
@@ -503,3 +471,51 @@
return map;
}
+
+jobject CreateJ::Set(std::vector<jobject> &objects)
+{
+ JNIEnv *env = JNIUtil::getEnv();
+ jclass clazz = env->FindClass("java/util/HashSet");
+ if (JNIUtil::isJavaExceptionThrown())
+ return NULL;
+
+ static jmethodID init_mid = 0;
+ if (init_mid == 0)
+ {
+ init_mid = env->GetMethodID(clazz, "<init>", "()V");
+ if (JNIUtil::isJavaExceptionThrown())
+ return NULL;
+ }
+
+ static jmethodID add_mid = 0;
+ if (add_mid == 0)
+ {
+ add_mid = env->GetMethodID(clazz, "add", "(Ljava/lang/Object;)Z");
+ if (JNIUtil::isJavaExceptionThrown())
+ return NULL;
+ }
+
+ jobject set = env->NewObject(clazz, init_mid);
+ if (JNIUtil::isJavaExceptionThrown())
+ return NULL;
+
+ std::vector<jobject>::const_iterator it;
+ for (it = objects.begin(); it < objects.end(); ++it)
+ {
+ jobject jthing = *it;
+
+ env->CallObjectMethod(set, add_mid, jthing);
+ if (JNIUtil::isJavaExceptionThrown())
+ return NULL;
+
+ env->DeleteLocalRef(jthing);
+ if (JNIUtil::isJavaExceptionThrown())
+ return NULL;
+ }
+
+ env->DeleteLocalRef(clazz);
+ if (JNIUtil::isJavaExceptionThrown())
+ return NULL;
+
+ return set;
+}
Modified: subversion/trunk/subversion/bindings/javahl/native/CreateJ.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/CreateJ.h?rev=918516&r1=918515&r2=918516&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/CreateJ.h (original)
+++ subversion/trunk/subversion/bindings/javahl/native/CreateJ.h Wed Mar 3 15:36:10 2010
@@ -30,6 +30,8 @@
#include <jni.h>
#include "svn_wc.h"
+#include <vector>
+
/**
* This class passes centralizes the creating of Java objects from
* Subversion's C structures.
@@ -56,6 +58,11 @@
static jobject
PropertyMap(apr_hash_t *prop_hash, apr_pool_t *pool);
+ /* This creates a set of Objects. It derefs the members of the vector
+ * after putting them in the set, so they caller doesn't need to. */
+ static jobject
+ Set(std::vector<jobject> &objects);
+
protected:
static jobject
ConflictVersion(const svn_wc_conflict_version_t *version);
Modified: subversion/trunk/subversion/bindings/javahl/native/SVNAdmin.cpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/SVNAdmin.cpp?rev=918516&r1=918515&r2=918516&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/SVNAdmin.cpp (original)
+++ subversion/trunk/subversion/bindings/javahl/native/SVNAdmin.cpp Wed Mar 3 15:36:10 2010
@@ -515,37 +515,12 @@
requestPool.pool()),
NULL);
- int count = apr_hash_count (locks);
-
JNIEnv *env = JNIUtil::getEnv();
jclass clazz = env->FindClass(JAVA_PACKAGE"/Lock");
if (JNIUtil::isJavaExceptionThrown())
return NULL;
- jclass sclazz = env->FindClass("java/util/Set");
- if (JNIUtil::isJavaExceptionThrown())
- return NULL;
-
- static jmethodID init_mid = 0;
- if (init_mid == 0)
- {
- init_mid = env->GetMethodID(sclazz, "<init>", "()V");
- if (JNIUtil::isJavaExceptionThrown())
- return NULL;
- }
-
- static jmethodID add_mid = 0;
- if (add_mid == 0)
- {
- add_mid = env->GetMethodID(sclazz, "add",
- "(Ljava/lang/Object;)Z");
- if (JNIUtil::isJavaExceptionThrown())
- return NULL;
- }
-
- jobject map = env->NewObject(sclazz, init_mid);
- if (JNIUtil::isJavaExceptionThrown())
- return NULL;
+ std::vector<jobject> jlocks;
for (hi = apr_hash_first (requestPool.pool(), locks);
hi;
@@ -556,24 +531,14 @@
svn_lock_t *lock = (svn_lock_t *)val;
jobject jLock = CreateJ::Lock(lock);
- env->CallObjectMethod(map, add_mid, jLock);
- if (JNIUtil::isJavaExceptionThrown())
- return NULL;
-
- env->DeleteLocalRef(jLock);
- if (JNIUtil::isJavaExceptionThrown())
- return NULL;
+ jlocks.push_back(jLock);
}
env->DeleteLocalRef(clazz);
if (JNIUtil::isJavaExceptionThrown())
return NULL;
- env->DeleteLocalRef(sclazz);
- if (JNIUtil::isJavaExceptionThrown())
- return NULL;
-
- return map;
+ return CreateJ::Set(jlocks);
}
void SVNAdmin::rmlocks(const char *path, Targets &locks)