From ad6660a639aba236c9d30485da1cd2bb1292ef83 Mon Sep 17 00:00:00 2001 From: Vladimir Levin Date: Thu, 18 Jan 2018 12:35:11 -0800 Subject: Use equal_range for factory lookups This patch uses equal_range instead of linear search to look up a factory entry by name. This does require a sort, but the expected usage is that the sort happens once and look ups happen many times. This improves performance on Chromium's oop deserialization of flattenables by about 10% R=reed@chromium.org Change-Id: I907f457a2ffb7d5b6d8261343099d982260b8415 Reviewed-on: https://skia-review.googlesource.com/96820 Reviewed-by: Mike Klein Commit-Queue: Mike Klein --- tests/FlattenableNameToFactory.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 tests/FlattenableNameToFactory.cpp (limited to 'tests/FlattenableNameToFactory.cpp') diff --git a/tests/FlattenableNameToFactory.cpp b/tests/FlattenableNameToFactory.cpp new file mode 100644 index 0000000000..d082504800 --- /dev/null +++ b/tests/FlattenableNameToFactory.cpp @@ -0,0 +1,24 @@ +/* + * Copyright 2018 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "SkFlattenable.h" +#include "Test.h" + +DEF_TEST(FlattenableNameToFactory, r) { + if (!SkFlattenable::NameToFactory("SkImageShader")) { + ERRORF(r, "SkFlattenable::NameToFactory() fails with SkImageShader."); + } + if (SkFlattenable::NameToFactory("AAA-non-existent")) { + ERRORF(r, "SkFlattenable::NameToFactory() succeeds with AAA-non-existent."); + } + if (SkFlattenable::NameToFactory("SkNonExistent")) { + ERRORF(r, "SkFlattenable::NameToFactory() succeeds with SkNonExistent"); + } + if (SkFlattenable::NameToFactory("ZZZ-non-existent")) { + ERRORF(r, "SkFlattenable::NameToFactory() succeeds with ZZZ-non-existent."); + } +} -- cgit v1.2.3