diff options
author | ajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-21 19:23:44 +0000 |
---|---|---|
committer | ajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-21 19:23:44 +0000 |
commit | 7296f2763bd40e560466f09836c7208c42d90f94 (patch) | |
tree | 142a03c36f75f42738206355a029707ad88cdffc /base/bind_unittest.nc | |
parent | 1fbbf963079bc977ea041b7e50ddf4666f6fec38 (diff) | |
download | chromium_src-7296f2763bd40e560466f09836c7208c42d90f94.zip chromium_src-7296f2763bd40e560466f09836c7208c42d90f94.tar.gz chromium_src-7296f2763bd40e560466f09836c7208c42d90f94.tar.bz2 |
Callback API Change: Reimplement Bind(); support IgnoreResult, full currying, and use less types.
The main API change IgnoreResult() and fully currying. See unittest for what the new API looks like. The rest of the changes are done to support that.
Previously, IgnoreReturn could not be used with WeakPtr<> Bind()s as it was applied after the fact to the Callback object. Now, IgnoreResult() wraps the function like Unretained().
As an incidental benefit, the new implementation gave us fully currying for free.
Also, the new implementation scales better when supporting higher arities of functions. The new type growth is:
(n^2 + 20n) / 2
as opposed to
(3n^2 + 17n) / 2
where n == arity.
For n = 6 and n=10, the new implementation has 81 and 155 templates respectively.
The old implementation had 105 and 235 templates respectively.
BUG=35233,98919,98542
TEST=existing unittests
Review URL: http://codereview.chromium.org/8483003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@110975 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/bind_unittest.nc')
-rw-r--r-- | base/bind_unittest.nc | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/base/bind_unittest.nc b/base/bind_unittest.nc index eba8747..069092c 100644 --- a/base/bind_unittest.nc +++ b/base/bind_unittest.nc @@ -4,6 +4,7 @@ #include "base/callback.h" #include "base/bind.h" +#include "base/memory/ref_counted.h" namespace base { @@ -21,10 +22,7 @@ class NoRef { int IntMethod0() { return 1; } }; -class HasRef : public NoRef { - public: - void AddRef(void) const {} - bool Release(void) const { return true; } +class HasRef : public NoRef, public base::RefCounted<HasRef> { }; class Parent { @@ -175,6 +173,9 @@ void WontCompile() { // Refcounted types should not be bound as a raw pointer. void WontCompile() { HasRef for_raw_ptr; + int a; + Callback<void(void)> ref_count_as_raw_ptr_a = + Bind(&VoidPolymorphic1<int*>, &a); Callback<void(void)> ref_count_as_raw_ptr = Bind(&VoidPolymorphic1<HasRef*>, &for_raw_ptr); } @@ -190,7 +191,7 @@ void WontCompile() { weak_ptr_with_non_void_return_type.Run(); } -#elif defined(NCTEST_DISALLOW_ASSIGN_DIFFERINT_TYPES) // [r"creating array with negative size"] +#elif defined(NCTEST_DISALLOW_ASSIGN_DIFFERINT_TYPES) // [r"invalid conversion from"] // Bind result cannot be assigned to Callbacks with a mismatching type. void WontCompile() { |