subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r1544501 - in /subversion/trunk/subversion/bindings/javahl/native: ExternalItem.cpp ExternalItem.hpp jniwrapper/jni_class_cache.cpp jniwrapper/jni_object.hpp
Date Fri, 22 Nov 2013 11:59:10 GMT
Author: brane
Date: Fri Nov 22 11:59:09 2013
New Revision: 1544501

URL: http://svn.apache.org/r1544501
Log:
Second round of converting newstyle JavaHL native classes to cache all
method and field IDs; ths time it's classes outside of jniwrapper.

[in subversion/bindings/javahl]
* native/jniwrapper/jni_object.hpp (ClassCache):
   Declare new cached classes: external_item.
* native/jniwrapper/jni_class_cache.cpp (ClassCache::ClassCache):
   Init members and call static initializers for wrapped classes:
   JavaHL::ExternalItem.

* native/ExternalItem.hpp, native/ExternalItem.cpp:
   Convert to init static method and field IDs and use
   the cached class reference.

Modified:
    subversion/trunk/subversion/bindings/javahl/native/ExternalItem.cpp
    subversion/trunk/subversion/bindings/javahl/native/ExternalItem.hpp
    subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_class_cache.cpp
    subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_object.hpp

Modified: subversion/trunk/subversion/bindings/javahl/native/ExternalItem.cpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/ExternalItem.cpp?rev=1544501&r1=1544500&r2=1544501&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/ExternalItem.cpp (original)
+++ subversion/trunk/subversion/bindings/javahl/native/ExternalItem.cpp Fri Nov 22 11:59:09
2013
@@ -31,39 +31,53 @@ namespace JavaHL {
 const char* const ExternalItem::m_class_name =
   JAVA_PACKAGE"/types/ExternalItem";
 
+::Java::MethodID ExternalItem::m_mid_ctor;
+::Java::FieldID ExternalItem::m_fid_target_dir;
+::Java::FieldID ExternalItem::m_fid_url;
+::Java::FieldID ExternalItem::m_fid_revision;
+::Java::FieldID ExternalItem::m_fid_peg_revision;
+
+void ExternalItem::static_init(::Java::Env env)
+{
+  const jclass cls = ::Java::ClassCache::get_external_item();
+  m_mid_ctor =
+    env.GetMethodID(cls, "<init>",
+                    "(ZLjava/lang/String;Ljava/lang/String;"
+                    "L"JAVA_PACKAGE"/types/Revision;"
+                    "L"JAVA_PACKAGE"/types/Revision;)V");
+  m_fid_target_dir = env.GetFieldID(cls, "targetDir", "Ljava/lang/String;");
+  m_fid_url = env.GetFieldID(cls, "url", "Ljava/lang/String;");
+  m_fid_revision = env.GetFieldID(cls, "revision",
+                                  "L"JAVA_PACKAGE"/types/Revision;");
+  m_fid_peg_revision = env.GetFieldID(cls, "pegRevision",
+                                      "L"JAVA_PACKAGE"/types/Revision;");
+}
+
 namespace {
-jstring get_string_field(::Java::Env env, jclass cls, jobject jthis,
-                         const char* field_name)
+inline jstring
+get_string_field(::Java::Env env, jobject jthis,
+                 const ::Java::FieldID& fid)
 {
-  return jstring(
-      env.GetObjectField(
-          jthis, env.GetFieldID(cls, field_name, "Ljava/lang/String;")));
+  return jstring(env.GetObjectField(jthis, fid));
 }
 
-svn_opt_revision_t get_revision_field(::Java::Env env,
-                                      jclass cls, jobject jthis,
-                                      const char* field_name)
+inline svn_opt_revision_t
+get_revision_field(::Java::Env env, jobject jthis,
+                   const ::Java::FieldID& fid)
 {
-  const jobject rev =  env.GetObjectField(
-      jthis, env.GetFieldID(cls, field_name,
-                            "L"JAVA_PACKAGE"/types/Revision;"));
+  const jobject rev =  env.GetObjectField(jthis, fid);
   return *Revision(rev).revision();
 }
 
-jobject make_external_item(::Java::Env env,
-                           const char* class_name,
-                           const char* target_dir,
-                           const char* url,
-                           const svn_opt_revision_t* revision,
-                           const svn_opt_revision_t* peg_revision)
+inline jobject
+make_external_item(::Java::Env env, const ::Java::MethodID& mid_ctor,
+                   const char* target_dir,
+                   const char* url,
+                   const svn_opt_revision_t* revision,
+                   const svn_opt_revision_t* peg_revision)
 {
-  const jclass cls = env.FindClass(class_name);
-  const jmethodID mid_ctor =
-    env.GetMethodID(cls, "<init>",
-                    "(ZLjava/lang/String;Ljava/lang/String;"
-                    "L"JAVA_PACKAGE"/types/Revision;"
-                    "L"JAVA_PACKAGE"/types/Revision;)V");
-  return env.NewObject(cls, mid_ctor, JNI_FALSE,
+  return env.NewObject(::Java::ClassCache::get_external_item(), mid_ctor,
+                       JNI_FALSE,
                        env.NewStringUTF(target_dir),
                        env.NewStringUTF(url),
                        Revision::makeJRevision(*revision),
@@ -72,11 +86,11 @@ jobject make_external_item(::Java::Env e
 } // anonymous namespace
 
 ExternalItem::ExternalItem(::Java::Env env, jobject jthis)
-  : Object(env, m_class_name, jthis),
-    m_target_dir(env, get_string_field(env, m_class, jthis, "targetDir")),
-    m_url(env, get_string_field(env, m_class, jthis, "url")),
-    m_revision(get_revision_field(env, m_class, jthis, "revision")),
-    m_peg_revision(get_revision_field(env, m_class, jthis, "pegRevision"))
+  : Object(env, ::Java::ClassCache::get_external_item(), jthis),
+    m_target_dir(env, get_string_field(env, jthis, m_fid_target_dir)),
+    m_url(env, get_string_field(env, jthis, m_fid_url)),
+    m_revision(get_revision_field(env, jthis, m_fid_revision)),
+    m_peg_revision(get_revision_field(env, jthis, m_fid_peg_revision))
 {}
 
 ExternalItem::ExternalItem(::Java::Env env,
@@ -84,8 +98,8 @@ ExternalItem::ExternalItem(::Java::Env e
                            const char* url,
                            const svn_opt_revision_t* revision,
                            const svn_opt_revision_t* peg_revision)
-  : Object(env, m_class_name,
-           make_external_item(env, m_class_name, target_dir, url,
+  : Object(env, ::Java::ClassCache::get_external_item(),
+           make_external_item(env, m_mid_ctor, target_dir, url,
                               revision, peg_revision)),
     m_target_dir(env, target_dir),
     m_url(env, url),

Modified: subversion/trunk/subversion/bindings/javahl/native/ExternalItem.hpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/ExternalItem.hpp?rev=1544501&r1=1544500&r2=1544501&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/ExternalItem.hpp (original)
+++ subversion/trunk/subversion/bindings/javahl/native/ExternalItem.hpp Fri Nov 22 11:59:09
2013
@@ -100,7 +100,14 @@ public:
   svn_wc_external_item2_t* get_external_item(SVN::Pool& pool) const;
 
 private:
+  friend class ::Java::ClassCache;
   static const char* const m_class_name;
+  static void static_init(::Java::Env env);
+  static ::Java::MethodID m_mid_ctor;
+  static ::Java::FieldID m_fid_target_dir;
+  static ::Java::FieldID m_fid_url;
+  static ::Java::FieldID m_fid_revision;
+  static ::Java::FieldID m_fid_peg_revision;
 
   ::Java::String m_target_dir;
   ::Java::String m_url;

Modified: subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_class_cache.cpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_class_cache.cpp?rev=1544501&r1=1544500&r2=1544501&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_class_cache.cpp (original)
+++ subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_class_cache.cpp Fri
Nov 22 11:59:09 2013
@@ -36,6 +36,7 @@
 #include "jni_string_map.hpp"
 
 #include "../SubversionException.hpp"
+#include "../ExternalItem.hpp"
 
 namespace Java {
 
@@ -111,7 +112,9 @@ ClassCache::ClassCache(Env env)
                                            ByteChannel::ByteBuffer),
 
     SVN_JAVAHL_JNIWRAPPER_CLASS_CACHE_INIT(subversion_exception,
-                                           ::JavaHL::SubversionException)
+                                           ::JavaHL::SubversionException),
+    SVN_JAVAHL_JNIWRAPPER_CLASS_CACHE_INIT(external_item,
+                                           ::JavaHL::ExternalItem)
 {
   m_instance = this;
   // no-op: Object::static_init(env);
@@ -134,6 +137,7 @@ ClassCache::ClassCache(Env env)
   ByteChannel::ByteBuffer::static_init(env);
 
   // no-op: ::JavaHL::SubversionException::static_init(env);
+  ::JavaHL::ExternalItem::static_init(env);
 }
 #undef SVN_JAVAHL_JNIWRAPPER_CLASS_CACHE_INIT
 

Modified: subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_object.hpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_object.hpp?rev=1544501&r1=1544500&r2=1544501&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_object.hpp (original)
+++ subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_object.hpp Fri Nov 22
11:59:09 2013
@@ -161,6 +161,7 @@ class ClassCache
   SVN_JAVAHL_JNIWRAPPER_CACHED_CLASS(byte_buffer);
 
   SVN_JAVAHL_JNIWRAPPER_CACHED_CLASS(subversion_exception);
+  SVN_JAVAHL_JNIWRAPPER_CACHED_CLASS(external_item);
 #undef SVN_JAVAHL_JNIWRAPPER_CACHED_CLASS
 
 public:



Mime
View raw message