diff options
author | Seigo Nonaka <nona@google.com> | 2023-11-04 12:27:17 +0900 |
---|---|---|
committer | Seigo Nonaka <nona@google.com> | 2023-11-13 11:33:20 +0900 |
commit | 66c35a4ecdc12be8ba01319920236450a7f410eb (patch) | |
tree | c46c40ee1e8140c46f68320c8103ba364eae2bf6 | |
parent | d27148d9ed3d653b6e8d95a769de0150be1104e9 (diff) | |
download | minikin-66c35a4ecdc12be8ba01319920236450a7f410eb.tar.gz |
Cache the flag value
Accessing flags in native is costly and should not be done during
layout calculation.
Bug: 308950033
Test: atest StaticLayoutGetOffsetForHorizontalPerfTest
Change-Id: I72ec6b3a531eff593311f2142d40351affcc638b
-rw-r--r-- | libs/minikin/FeatureFlags.h | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/libs/minikin/FeatureFlags.h b/libs/minikin/FeatureFlags.h index 3c2e455..3218d2b 100644 --- a/libs/minikin/FeatureFlags.h +++ b/libs/minikin/FeatureFlags.h @@ -23,21 +23,21 @@ namespace features { -inline bool phrase_strict_fallback() { #ifdef __ANDROID__ - return com_android_text_flags_phrase_strict_fallback(); -#else - return true; -#endif // __ANDROID__ -} +#define DEFINE_FEATURE_FLAG_ACCESSOROR(feature_name) \ + inline bool feature_name() { \ + static bool flag = com_android_text_flags_##feature_name(); \ + return flag; \ + } +#else // __ANDROID__ +#define DEFINE_FEATURE_FLAG_ACCESSOROR(feature_name) \ + inline bool feature_name() { \ + return true; \ + } +#endif // __ANDROID__ -inline bool word_style_auto() { -#ifdef __ANDROID__ - return com_android_text_flags_word_style_auto(); -#else - return true; -#endif // __ANDROID__ -} +DEFINE_FEATURE_FLAG_ACCESSOROR(phrase_strict_fallback) +DEFINE_FEATURE_FLAG_ACCESSOROR(word_style_auto) } // namespace features |