1. Pypy
  2. Untitled project
  3. pypy

Commits

wlav  committed 06e52a5

optimization: prevent copies of TClassRef handles

  • Participants
  • Parent commits bf6fc9a
  • Branches reflex-support

Comments (0)

Files changed (1)

File pypy/module/cppyy/src/cintcwrapper.cxx

View file
  • Ignore whitespace
     return cppstring_to_cstring(true_name);
 }
 
-static inline TClassRef type_from_handle(cppyy_type_t handle) {
+static inline TClassRef& type_from_handle(cppyy_type_t handle) {
     assert((ClassRefs_t::size_type)handle < g_classrefs.size());
     return g_classrefs[(ClassRefs_t::size_type)handle];
 }
 
 static inline TFunction* type_get_method(cppyy_type_t handle, cppyy_index_t idx) {
-    TClassRef cr = type_from_handle(handle);
+    TClassRef& cr = type_from_handle(handle);
     if (cr.GetClass())
         return (TFunction*)cr->GetListOfMethods()->At(idx);
     return (TFunction*)idx;
 
 /* name to opaque C++ scope representation -------------------------------- */
 int cppyy_num_scopes(cppyy_scope_t handle) {
-    TClassRef cr = type_from_handle(handle);
+    TClassRef& cr = type_from_handle(handle);
     if (cr.GetClass()) {
         /* not supported as CINT does not store classes hierarchically */
         return 0;
 }
 
 char* cppyy_scope_name(cppyy_scope_t handle, int iscope) {
-    TClassRef cr = type_from_handle(handle);
+    TClassRef& cr = type_from_handle(handle);
     if (cr.GetClass()) {
         /* not supported as CINT does not store classes hierarchically */
         assert(!"scope name lookup not supported on inner scopes");
     if (icr != g_classref_indices.end())
         return (cppyy_type_t)icr->second;
 
-    // use TClass directly, to enable auto-loading
+    if (strcmp(scope_name, "#define") == 0)
+        return (cppyy_type_t)NULL;
+
+     // use TClass directly, to enable auto-loading
     TClassRef cr(TClass::GetClass(scope_name, kTRUE, kTRUE));
     if (!cr.GetClass())
         return (cppyy_type_t)NULL;
 }
 
 cppyy_type_t cppyy_actual_class(cppyy_type_t klass, cppyy_object_t obj) {
-    TClassRef cr = type_from_handle(klass);
+    TClassRef& cr = type_from_handle(klass);
     TClass* clActual = cr->GetActualClass( (void*)obj );
     if (clActual && clActual != cr.GetClass()) {
         // TODO: lookup through name should not be needed
 
 /* memory management ------------------------------------------------------ */
 cppyy_object_t cppyy_allocate(cppyy_type_t handle) {
-    TClassRef cr = type_from_handle(handle);
+    TClassRef& cr = type_from_handle(handle);
     return (cppyy_object_t)malloc(cr->Size());
 }
 
 }
 
 void cppyy_destruct(cppyy_type_t handle, cppyy_object_t self) {
-    TClassRef cr = type_from_handle(handle);
+    TClassRef& cr = type_from_handle(handle);
     cr->Destructor((void*)self, true);
 }
 
 
 /* scope reflection information ------------------------------------------- */
 int cppyy_is_namespace(cppyy_scope_t handle) {
-    TClassRef cr = type_from_handle(handle);
+    TClassRef& cr = type_from_handle(handle);
     if (cr.GetClass() && cr->GetClassInfo())
         return cr->Property() & G__BIT_ISNAMESPACE;
     if (strcmp(cr.GetClassName(), "") == 0)
 
 /* type/class reflection information -------------------------------------- */
 char* cppyy_final_name(cppyy_type_t handle) {
-    TClassRef cr = type_from_handle(handle);
+    TClassRef& cr = type_from_handle(handle);
     if (cr.GetClass() && cr->GetClassInfo()) {
         std::string true_name = G__TypeInfo(cr->GetName()).TrueName();
         std::string::size_type pos = true_name.rfind("::");
 }
 
 char* cppyy_scoped_final_name(cppyy_type_t handle) {
-    TClassRef cr = type_from_handle(handle);
+    TClassRef& cr = type_from_handle(handle);
     if (cr.GetClass() && cr->GetClassInfo()) {
         std::string true_name = G__TypeInfo(cr->GetName()).TrueName();
         return cppstring_to_cstring(true_name);
 }
 
 int cppyy_num_bases(cppyy_type_t handle) {
-    TClassRef cr = type_from_handle(handle);
+    TClassRef& cr = type_from_handle(handle);
     if (cr.GetClass() && cr->GetListOfBases() != 0)
         return cr->GetListOfBases()->GetSize();
     return 0;
 }
 
 char* cppyy_base_name(cppyy_type_t handle, int base_index) {
-    TClassRef cr = type_from_handle(handle);
+    TClassRef& cr = type_from_handle(handle);
     TBaseClass* b = (TBaseClass*)cr->GetListOfBases()->At(base_index);
     return type_cppstring_to_cstring(b->GetName());
 }
 
 int cppyy_is_subtype(cppyy_type_t derived_handle, cppyy_type_t base_handle) {
-    TClassRef derived_type = type_from_handle(derived_handle);
-    TClassRef base_type = type_from_handle(base_handle);
+    TClassRef& derived_type = type_from_handle(derived_handle);
+    TClassRef& base_type = type_from_handle(base_handle);
     return derived_type->GetBaseClass(base_type) != 0;
 }
 
 size_t cppyy_base_offset(cppyy_type_t derived_handle, cppyy_type_t base_handle,
                        cppyy_object_t address, int /* direction */) {
     // WARNING: CINT can not handle actual dynamic casts!
-    TClassRef derived_type = type_from_handle(derived_handle);
-    TClassRef base_type = type_from_handle(base_handle);
+    TClassRef& derived_type = type_from_handle(derived_handle);
+    TClassRef& base_type = type_from_handle(base_handle);
 
     long offset = 0;
 
 
 /* method/function reflection information --------------------------------- */
 int cppyy_num_methods(cppyy_scope_t handle) {
-    TClassRef cr = type_from_handle(handle);
+    TClassRef& cr = type_from_handle(handle);
     if (cr.GetClass() && cr->GetListOfMethods())
         return cr->GetListOfMethods()->GetSize();
     else if (strcmp(cr.GetClassName(), "") == 0) {
 }
 
 cppyy_index_t cppyy_method_index_at(cppyy_scope_t handle, int imeth) {
-    TClassRef cr = type_from_handle(handle);
+    TClassRef& cr = type_from_handle(handle);
     if (cr.GetClass())
         return (cppyy_index_t)imeth;
     return (cppyy_index_t)&g_globalfuncs[imeth];
 
 cppyy_index_t* cppyy_method_indices_from_name(cppyy_scope_t handle, const char* name) {
     std::vector<cppyy_index_t> result;
-    TClassRef cr = type_from_handle(handle);
+    TClassRef& cr = type_from_handle(handle);
     if (cr.GetClass()) {
         gInterpreter->UpdateListOfMethods(cr.GetClass());
         int imeth = 0;
 }
 
 char* cppyy_method_result_type(cppyy_scope_t handle, cppyy_index_t idx) {
-    TClassRef cr = type_from_handle(handle);
+    TClassRef& cr = type_from_handle(handle);
     if (cr.GetClass() && cppyy_is_constructor(handle, idx))
         return cppstring_to_cstring("constructor");
     TFunction* f = type_get_method(handle, idx);
 }
 
 char* cppyy_method_signature(cppyy_scope_t handle, cppyy_index_t idx) {
-    TClassRef cr = type_from_handle(handle);
+    TClassRef& cr = type_from_handle(handle);
     TFunction* f = type_get_method(handle, idx);
     std::ostringstream sig;
     if (cr.GetClass() && cr->GetClassInfo()
 
 
 cppyy_method_t cppyy_get_method(cppyy_scope_t handle, cppyy_index_t idx) {
-    TClassRef cr = type_from_handle(handle);
+    TClassRef& cr = type_from_handle(handle);
     TFunction* f = type_get_method(handle, idx);
     if (cr && cr.GetClass() && !cr->IsLoaded()) {
         G__ClassInfo* gcl = (G__ClassInfo*)cr->GetClassInfo();
 }
 
 cppyy_index_t cppyy_get_global_operator(cppyy_scope_t scope, cppyy_scope_t lc, cppyy_scope_t rc, const char* op) {
-    TClassRef lccr = type_from_handle(lc);
-    TClassRef rccr = type_from_handle(rc);
+    TClassRef& lccr = type_from_handle(lc);
+    TClassRef& rccr = type_from_handle(rc);
 
     if (!lccr.GetClass() || !rccr.GetClass() || scope != GLOBAL_HANDLE)
         return (cppyy_index_t)-1;  // (void*)-1 is in kernel space, so invalid as a method handle
 
 /* method properties -----------------------------------------------------  */
 int cppyy_is_constructor(cppyy_type_t handle, cppyy_index_t idx) {
-    TClassRef cr = type_from_handle(handle);
+    TClassRef& cr = type_from_handle(handle);
     TMethod* m = (TMethod*)cr->GetListOfMethods()->At(idx);
     return strcmp(m->GetName(), ((G__ClassInfo*)cr->GetClassInfo())->Name()) == 0;
 }
 
 int cppyy_is_staticmethod(cppyy_type_t handle, cppyy_index_t idx) {
-    TClassRef cr = type_from_handle(handle);
+    TClassRef& cr = type_from_handle(handle);
     TMethod* m = (TMethod*)cr->GetListOfMethods()->At(idx);
     return m->Property() & G__BIT_ISSTATIC;
 }
 
 /* data member reflection information ------------------------------------- */
 int cppyy_num_datamembers(cppyy_scope_t handle) {
-    TClassRef cr = type_from_handle(handle);
+    TClassRef& cr = type_from_handle(handle);
     if (cr.GetClass() && cr->GetListOfDataMembers())
         return cr->GetListOfDataMembers()->GetSize();
     else if (strcmp(cr.GetClassName(), "") == 0) {
 }
 
 char* cppyy_datamember_name(cppyy_scope_t handle, int datamember_index) {
-    TClassRef cr = type_from_handle(handle);
+    TClassRef& cr = type_from_handle(handle);
     if (cr.GetClass()) {
         TDataMember* m = (TDataMember*)cr->GetListOfDataMembers()->At(datamember_index);
         return cppstring_to_cstring(m->GetName());
 }
 
 char* cppyy_datamember_type(cppyy_scope_t handle, int datamember_index) {
-    TClassRef cr = type_from_handle(handle);
+    TClassRef& cr = type_from_handle(handle);
     if (cr.GetClass())  {
         TDataMember* m = (TDataMember*)cr->GetListOfDataMembers()->At(datamember_index);
         std::string fullType = m->GetFullTypeName();
 }
 
 size_t cppyy_datamember_offset(cppyy_scope_t handle, int datamember_index) {
-    TClassRef cr = type_from_handle(handle);
+    TClassRef& cr = type_from_handle(handle);
     if (cr.GetClass()) {
         TDataMember* m = (TDataMember*)cr->GetListOfDataMembers()->At(datamember_index);
         return (size_t)m->GetOffsetCint();
 }
 
 int cppyy_datamember_index(cppyy_scope_t handle, const char* name) {
-    TClassRef cr = type_from_handle(handle);
+    TClassRef& cr = type_from_handle(handle);
     if (cr.GetClass()) {
         // called from updates; add a hard reset as the code itself caches in
         // Class (TODO: by-pass ROOT/meta)
 
 /* data member properties ------------------------------------------------  */
 int cppyy_is_publicdata(cppyy_scope_t handle, int datamember_index) {
-    TClassRef cr = type_from_handle(handle);
+    TClassRef& cr = type_from_handle(handle);
     if (cr.GetClass()) {
         TDataMember* m = (TDataMember*)cr->GetListOfDataMembers()->At(datamember_index);
         return m->Property() & G__BIT_ISPUBLIC;
 }
 
 int cppyy_is_staticdata(cppyy_scope_t handle, int datamember_index) {
-    TClassRef cr = type_from_handle(handle);
+    TClassRef& cr = type_from_handle(handle);
     if (cr.GetClass()) {
         TDataMember* m = (TDataMember*)cr->GetListOfDataMembers()->At(datamember_index);
         return m->Property() & G__BIT_ISSTATIC;