From 2ff1fcede1e9525285c5de1f35fb2dcb0fab32bd Mon Sep 17 00:00:00 2001 From: reed Date: Thu, 11 Dec 2014 07:07:37 -0800 Subject: Defer saves() until they're needed patch from issue 759443006 at patchset 40001 (http://crrev.com/759443006#ps40001) BUG=skia: Review URL: https://codereview.chromium.org/767333002 --- tests/RecordTestUtils.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'tests/RecordTestUtils.h') diff --git a/tests/RecordTestUtils.h b/tests/RecordTestUtils.h index 0575b83cdd..4bab8e4a39 100644 --- a/tests/RecordTestUtils.h +++ b/tests/RecordTestUtils.h @@ -28,4 +28,28 @@ static const T* assert_type(skiatest::Reporter* r, const SkRecord& record, unsig return reader.ptr; } +template struct MatchType { + template int operator()(const T&) { return 0; } + int operator()(const DrawT&) { return 1; } +}; + +template int count_instances_of_type(const SkRecord& record) { + MatchType matcher; + int counter = 0; + for (unsigned i = 0; i < record.count(); i++) { + counter += record.visit(i, matcher); + } + return counter; +} + +template int find_first_instances_of_type(const SkRecord& record) { + MatchType matcher; + for (unsigned i = 0; i < record.count(); i++) { + if (record.visit(i, matcher)) { + return i; + } + } + return -1; +} + #endif//RecordTestUtils_DEFINED -- cgit v1.2.3