From bb97494737ae2693e2589e3f8781fc128dc72aa8 Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Wed, 15 Nov 2000 17:25:19 +0000 Subject: [PATCH] Updated the BoundFunction::create() optimization and enabled it so it could actually be used! [SVN r8219] --- functions.cpp | 25 +++++++++++-------------- functions.h | 4 ++-- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/functions.cpp b/functions.cpp index 912cd087..4976a2cd 100644 --- a/functions.cpp +++ b/functions.cpp @@ -97,20 +97,17 @@ PyObject* Function::call(PyObject* args, PyObject* keywords) const return 0; } -Ptr BoundFunction::create(Ptr target, Ptr fn) +BoundFunction* BoundFunction::create(const Ptr& target, const Ptr& fn) { - BoundFunction* result = free_list; - if (result != 0) - { - free_list = result->m_free_list_link; - result->m_target = target; - result->m_unbound_function = fn; - } - else - { - result = new BoundFunction(target, fn); - } - return Ptr(result, Ptr::new_ref); + BoundFunction* const result = free_list; + if (result == 0) + return new BoundFunction(target, fn); + + free_list = result->m_free_list_link; + result->m_target = target; + result->m_unbound_function = fn; + Py_INCREF(result); + return result; } // The singleton class whose instance represents the type of BoundFunction @@ -126,7 +123,7 @@ private: // TypeObject hook override void dealloc(BoundFunction*) const; }; -BoundFunction::BoundFunction(Ptr target, Ptr fn) +BoundFunction::BoundFunction(const Ptr& target, const Ptr& fn) : PythonObject(TypeObject::singleton()), m_target(target), m_unbound_function(fn), diff --git a/functions.h b/functions.h index 1cf52407..9f8add61 100644 --- a/functions.h +++ b/functions.h @@ -201,9 +201,9 @@ namespace detail { class BoundFunction : public PythonObject { public: - static Ptr create(Ptr target, Ptr fn); + static BoundFunction* create(const Ptr& target, const Ptr& fn); - BoundFunction(Ptr target, Ptr fn); + BoundFunction(const Ptr& target, const Ptr& fn); PyObject* call(PyObject*args, PyObject* keywords) const; PyObject* getattr(const char* name) const;