Avoid allocating an SkString buffer for the TextStyle default font family
Change-Id: I3aa121bd5f84b9f9fdf21e3bdea4223136f47f43
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/370903
Reviewed-by: Julia Lavrova <jlavrova@google.com>
Commit-Queue: Jason Simmons <jsimmons@google.com>
diff --git a/modules/skparagraph/include/TextStyle.h b/modules/skparagraph/include/TextStyle.h
index b43a41f..ae6e854 100644
--- a/modules/skparagraph/include/TextStyle.h
+++ b/modules/skparagraph/include/TextStyle.h
@@ -243,6 +243,8 @@
void setPlaceholder() { fIsPlaceholder = true; }
private:
+ static const std::vector<SkString> kDefaultFontFamilies;
+
Decoration fDecoration = {
TextDecoration::kNoDecoration,
// TODO: switch back to kGaps when (if) switching flutter to skparagraph
@@ -255,7 +257,8 @@
SkFontStyle fFontStyle;
- std::vector<SkString> fFontFamilies = { SkString(DEFAULT_FONT_FAMILY) };
+ std::vector<SkString> fFontFamilies = kDefaultFontFamilies;
+
SkScalar fFontSize = 14.0;
SkScalar fHeight = 1.0;
bool fHeightOverride = false;
diff --git a/modules/skparagraph/src/TextStyle.cpp b/modules/skparagraph/src/TextStyle.cpp
index 0299f46..afb4c37 100644
--- a/modules/skparagraph/src/TextStyle.cpp
+++ b/modules/skparagraph/src/TextStyle.cpp
@@ -6,6 +6,8 @@
namespace skia {
namespace textlayout {
+const std::vector<SkString> TextStyle::kDefaultFontFamilies = { SkString(DEFAULT_FONT_FAMILY) };
+
TextStyle::TextStyle(const TextStyle& other, bool placeholder) {
fColor = other.fColor;
fFontSize = other.fFontSize;