@@ -15,26 +15,34 @@ from .array cimport _registry_assign_init as assign_init
1515
1616assign_init()
1717
18- cdef _publish_callables(mod, registry_entry entry = registered()):
19- for pair in entry:
20- if (pair.second.is_namespace()):
21- try :
22- new_mod = sys.modules[mod.__name__ + ' .' + pair.first]
23- except KeyError :
24- new_mod = imp.new_module(pair.first)
25- _publish_callables(new_mod, pair.second)
26- setattr (mod, pair.first, new_mod)
27- else :
28- setattr (mod, pair.first, wrap(pair.second.value()))
29-
30- def publish_callables (mod ):
31- return _publish_callables(mod, registered())
32-
33- cdef void observer(const char * name, registry_entry * entry) with gil:
34- from . import __name__
35- mod = sys.modules[__name__ ]
36-
37- if entry.is_namespace():
38- _publish_callables(mod, dereference(entry))
39-
40- registered().observe(& observer)
18+ from libcpp.map cimport map
19+ from libcpp.pair cimport pair
20+ from libcpp.string cimport string
21+
22+ from cython.operator import preincrement
23+
24+ cdef void add_one(registry_entry * parent_entry, const char * name, registry_entry * entry) with gil:
25+ if (entry.is_namespace()):
26+ try :
27+ new_mod = sys.modules[entry.path()]
28+ except KeyError :
29+ new_mod = imp.new_module(entry.path())
30+ sys.modules[entry.path()] = new_mod
31+ _publish_callables(dereference(entry))
32+ if (not parent_entry.path().empty()):
33+ mod = sys.modules[parent_entry.path()]
34+ setattr (mod, name, new_mod)
35+ else :
36+ mod = sys.modules[parent_entry.path()]
37+ setattr (mod, name, wrap(entry.value()))
38+
39+ cdef _publish_callables(registry_entry & entry):
40+ entry.observe(& add_one)
41+
42+ cdef map [string, registry_entry].iterator it = entry.begin()
43+ while (it != entry.end()):
44+ add_one(& entry, dereference(it).first.c_str(), & dereference(it).second)
45+ preincrement(it)
46+
47+ def publish_callables ():
48+ return _publish_callables(registered())
0 commit comments