Dramatically sped up all STL containers when
they contain swig::GC_VALUEs. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9824 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
6a01528488
commit
1cf8d3dd36
1 changed files with 29 additions and 2 deletions
|
|
@ -82,6 +82,9 @@ namespace swig {
|
||||||
namespace swig {
|
namespace swig {
|
||||||
class GC_VALUE {
|
class GC_VALUE {
|
||||||
protected:
|
protected:
|
||||||
|
// Hash of all GC_VALUE's currently in use
|
||||||
|
static VALUE _hash;
|
||||||
|
|
||||||
VALUE _obj;
|
VALUE _obj;
|
||||||
|
|
||||||
static ID hash_id;
|
static ID hash_id;
|
||||||
|
|
@ -118,6 +121,22 @@ namespace swig {
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
static void initialize()
|
||||||
|
{
|
||||||
|
if ( _hash == Qnil )
|
||||||
|
{
|
||||||
|
_hash = rb_hash_new();
|
||||||
|
rb_gc_register_address( &_hash );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// this function is never called. Provided for symmetry only.
|
||||||
|
static void cleanup()
|
||||||
|
{
|
||||||
|
rb_gc_unregister_address( &_hash );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
GC_VALUE() :_obj( Qnil )
|
GC_VALUE() :_obj( Qnil )
|
||||||
{
|
{
|
||||||
GC_register();
|
GC_register();
|
||||||
|
|
@ -146,12 +165,14 @@ namespace swig {
|
||||||
|
|
||||||
void GC_register()
|
void GC_register()
|
||||||
{
|
{
|
||||||
rb_gc_register_address( &_obj );
|
if ( TYPE(_obj) != T_DATA ) return;
|
||||||
|
rb_hash_aset( _hash, _obj, Qtrue );
|
||||||
}
|
}
|
||||||
|
|
||||||
void GC_unregister()
|
void GC_unregister()
|
||||||
{
|
{
|
||||||
rb_gc_unregister_address( &_obj );
|
if ( TYPE(_obj) != T_DATA ) return;
|
||||||
|
rb_hash_delete( _hash, _obj );
|
||||||
}
|
}
|
||||||
|
|
||||||
operator VALUE() const
|
operator VALUE() const
|
||||||
|
|
@ -297,6 +318,9 @@ namespace swig {
|
||||||
|
|
||||||
ID GC_VALUE::lshift_id = rb_intern("<<");
|
ID GC_VALUE::lshift_id = rb_intern("<<");
|
||||||
ID GC_VALUE::rshift_id = rb_intern(">>");
|
ID GC_VALUE::rshift_id = rb_intern(">>");
|
||||||
|
|
||||||
|
VALUE GC_VALUE::_hash = Qnil;
|
||||||
|
|
||||||
typedef GC_VALUE LANGUAGE_OBJ;
|
typedef GC_VALUE LANGUAGE_OBJ;
|
||||||
|
|
||||||
} // namespace swig
|
} // namespace swig
|
||||||
|
|
@ -304,6 +328,9 @@ namespace swig {
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
|
||||||
|
%init {
|
||||||
|
swig::GC_VALUE::initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue