Python -builtin __contains__ fix for map and set like containers.
Fix when using -builtin and wrapping std::map, std::set, std::unordered_map or std::unordered_set to ensure __contains__ is called. This is a wrapper for the STL container's find method. Without it, Python will do its own slower sequence search.
This commit is contained in:
parent
333209595d
commit
4715a4e72c
8 changed files with 76 additions and 2 deletions
|
|
@ -131,6 +131,10 @@
|
|||
%swig_sequence_forward_iterator(Map);
|
||||
%swig_container_methods(Map)
|
||||
|
||||
#if defined(SWIGPYTHON_BUILTIN)
|
||||
%feature("python:slot", "sq_contains", functype="objobjproc") __contains__;
|
||||
#endif
|
||||
|
||||
%extend {
|
||||
mapped_type __getitem__(const key_type& key) const throw (std::out_of_range) {
|
||||
Map::const_iterator i = self->find(key);
|
||||
|
|
@ -204,7 +208,6 @@
|
|||
return itemList;
|
||||
}
|
||||
|
||||
// Python 2.2 methods
|
||||
bool __contains__(const key_type& key) {
|
||||
return self->find(key) != self->end();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue