Drastically simplify and optimize object creation and destruction

Don't populate the typenames array for each and every created object and don't
search it when deleting every object, this is O(N) in number of classes and is
completely impractical for any big library where N can easily be several
thousands. Use destructor function which will correctly destroy the object
instead.

Also don't store each created objects in the global registry, there doesn't
seem to be any point in it.

And, in fact, don't bother with the typenames at all, just use another
pseudo-virtual function for checking whether a class inherits from a class
with the given name.

There is unfortunately one problem with the new approach: it doesn't work when
the same C++ type is wrapped under different names as this results in multiple
specializations of SWIG_derives_from<> for this type. But this is a relatively
rare situation (but which does arise in template_default2 unit test, which had
to be disabled) and could be fixed in the future by completely resolving the
type, including the default template parameters values, and checking if
SWIG_derives_from had been already specialized for it. In the meanwhile, this
regression is not a big deal compared to the advantages of the new approach.
This commit is contained in:
Vadim Zeitlin 2016-04-14 01:41:08 +02:00
commit 818b399c9e
6 changed files with 150 additions and 298 deletions

View file

@ -95,6 +95,7 @@ FAILING_CPP_TESTS := \
special_variables \
template_arg_typename \
template_basic \
template_default2 \
template_explicit \
template_ns4 \
template_tbase_template \