Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(408)

Side by Side Diff: tests/FunctionTest.cpp

Issue 1048243002: small-object optimization for SkFunction (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: windows Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/utils/SkTLogic.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkFunction.h" 8 #include "SkFunction.h"
9 #include "Test.h" 9 #include "Test.h"
10 10
11 static void test_add_five(skiatest::Reporter* r, SkFunction<int(int)>&& f) { 11 static void test_add_five(skiatest::Reporter* r, SkFunction<int(int)>&& f) {
12 REPORTER_ASSERT(r, f(3) == 8);
12 REPORTER_ASSERT(r, f(4) == 9); 13 REPORTER_ASSERT(r, f(4) == 9);
13 } 14 }
14 15
15 static int add_five(int x) { return x + 5; } 16 static int add_five(int x) { return x + 5; }
16 17
17 struct AddFive { 18 struct AddFive {
18 int operator()(int x) { return x + 5; }; 19 int operator()(int x) { return x + 5; };
19 }; 20 };
20 21
21 DEF_TEST(Function, r) { 22 DEF_TEST(Function, r) {
22 // We should be able to turn a static function, an explicit functor, or a la mbda 23 // We should be able to turn a static function, an explicit functor, or a la mbda
23 // all into an SkFunction equally well. 24 // all into an SkFunction equally well.
24 test_add_five(r, SkFunction<int(int)>(&add_five)); 25 test_add_five(r, SkFunction<int(int)>(&add_five));
25 test_add_five(r, SkFunction<int(int)>(AddFive())); 26 test_add_five(r, SkFunction<int(int)>(AddFive()));
26 test_add_five(r, SkFunction<int(int)>([](int x) { return x + 5; })); 27 test_add_five(r, SkFunction<int(int)>([](int x) { return x + 5; }));
28
29 // AddFive and the lambda above are both small enough to test small-object o ptimization.
30 // Now test a lambda that's much too large for the small-object optimization .
31 int a = 1, b = 1, c = 1, d = 1, e = 1;
32 test_add_five(r, SkFunction<int(int)>([&](int x) { return x + a + b + c + d + e; }));
27 } 33 }
OLDNEW
« no previous file with comments | « src/utils/SkTLogic.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698