From 9753dd74387884987c6ea801dc146a2baec86001 Mon Sep 17 00:00:00 2001 From: Tim Murray Date: Mon, 27 Feb 2023 11:33:46 -0800 Subject: [PATCH] FontScaleConverterFactoryTest: 15x perf increase Most of the time is spent in object allocation for the assert. Check to see if the calculation would fail, and only actually run the assert if it fails. Test: atest FontScaleConverterFactoryTest#allFeasibleScalesAndConversionsDoNotCrash Bug: 270054472 Change-Id: Id879c5442869766ec89e5e8173152d2db6631fd4 --- .../content/res/FontScaleConverterFactoryTest.kt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/core/tests/coretests/src/android/content/res/FontScaleConverterFactoryTest.kt b/core/tests/coretests/src/android/content/res/FontScaleConverterFactoryTest.kt index ef106bc7cb73b..cd7abeea63d3a 100644 --- a/core/tests/coretests/src/android/content/res/FontScaleConverterFactoryTest.kt +++ b/core/tests/coretests/src/android/content/res/FontScaleConverterFactoryTest.kt @@ -90,9 +90,13 @@ class FontScaleConverterFactoryTest { } .forEach { (table, sp) -> try { - assertWithMessage("convertSpToDp(%s) on table: %s", sp, table) - .that(table.convertSpToDp(sp)) - .isFinite() + // Truth is slow because it creates a bunch of + // objects. Don't use it unless we need to. + if (!table.convertSpToDp(sp).isFinite()) { + assertWithMessage("convertSpToDp(%s) on table: %s", sp, table) + .that(table.convertSpToDp(sp)) + .isFinite() + } } catch (e: Exception) { throw AssertionError("Exception during convertSpToDp($sp) on table: $table", e) }