@@ -222,24 +222,26 @@ Module <- function( module, PACKAGE = methods::getPackageName(where), where = to
222222
223223 fields <- cpp_fields( CLASS , where )
224224 methods <- cpp_refMethods(CLASS , where )
225- generator <- methods :: setRefClass( clname ,
226- fields = fields ,
227- contains = " C++Object" ,
228- methods = methods ,
229- where = where
230- )
231225 # just to make codetools happy
232226 .self <- .refClassDef <- NULL
233- generator $ methods(initialize =
227+ # Supply 'initialize' together with the other methods so that the
228+ # reference class is analysed once, instead of a second full pass
229+ # through refClassInformation() in generator$methods(...)
230+ methods [[" initialize" ]] <-
234231 if (cpp_hasDefaultConstructor(CLASS ))
235232 function (... ) Rcpp :: cpp_object_initializer(.self ,.refClassDef , ... )
236233 else
237234 function (... ) {
238235 if (nargs()) Rcpp :: cpp_object_initializer(.self ,.refClassDef , ... )
239236 else Rcpp :: cpp_object_dummy(.self , .refClassDef ) # #nocov
240237 }
241- )
242238 rm( .self , .refClassDef )
239+ generator <- methods :: setRefClass( clname ,
240+ fields = fields ,
241+ contains = " C++Object" ,
242+ methods = methods ,
243+ where = where
244+ )
243245
244246 classDef <- methods :: getClass(clname )
245247 # # non-public (static) fields in class representation
@@ -281,7 +283,10 @@ Module <- function( module, PACKAGE = methods::getPackageName(where), where = to
281283 CLASS <- classes [[i ]]
282284 clname <- CLASS @ .Data
283285 demangled_name <- sub( " ^Rcpp_" , " " , clname )
284- .classes_map [[ CLASS @ typeid ]] <- storage [[ demangled_name ]] <- .get_Module_Class( module , demangled_name , xp )
286+ # reuse the C++Class object already built by Module__classes_info
287+ # rather than rebuilding it (and all of its method/field objects)
288+ CLASS @ generator <- generators [[ clname ]]
289+ .classes_map [[ CLASS @ typeid ]] <- storage [[ demangled_name ]] <- CLASS
285290
286291 # exposing enums values as CLASS.VALUE
287292 # (should really be CLASS$value but I don't know how to do it)
0 commit comments