mirror of
https://github.com/panda3d/panda3d.git
synced 2025-09-30 16:58:40 -04:00
small optimization: has_method cache
This commit is contained in:
parent
efdeacb577
commit
563bd81b68
@ -16,7 +16,7 @@
|
||||
#include <sstream>
|
||||
|
||||
|
||||
static const bool debug_xml_output = true;
|
||||
static const bool debug_xml_output = false;
|
||||
|
||||
#define DO_BINARY_XML 1
|
||||
|
||||
|
@ -189,6 +189,14 @@ set_property(const string &property, P3D_object *value) {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool P3DPythonObject::
|
||||
has_method(const string &method_name) {
|
||||
// First, check the cache.
|
||||
pair<HasMethod::iterator, bool> cresult = _has_method.insert(HasMethod::value_type(method_name, false));
|
||||
HasMethod::iterator hi = cresult.first;
|
||||
if (!cresult.second) {
|
||||
// Already cached.
|
||||
return (*hi).second;
|
||||
}
|
||||
|
||||
bool bresult = false;
|
||||
|
||||
P3D_object *params[1];
|
||||
@ -202,6 +210,11 @@ has_method(const string &method_name) {
|
||||
P3D_OBJECT_DECREF(result);
|
||||
}
|
||||
|
||||
// Save the cached result, so we don't have to keep asking this
|
||||
// question. We assume that the set of methods on an object don't
|
||||
// change substantially, so we can get away with keeping this cache.
|
||||
(*hi).second = bresult;
|
||||
|
||||
return bresult;
|
||||
}
|
||||
|
||||
|
@ -57,6 +57,9 @@ public:
|
||||
private:
|
||||
P3DSession *_session;
|
||||
int _object_id;
|
||||
|
||||
typedef map<string, bool> HasMethod;
|
||||
HasMethod _has_method;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user