SK_ONCE for SkMatrix::I()
Going to start doing these in progressively larger and larger bulk,
but I figured the first few changes probably merit caution.
BUG=
R=reed@google.com, bungeman@google.com
Author: mtklein@google.com
Review URL: https://codereview.chromium.org/26905002
git-svn-id: http://skia.googlecode.com/svn/trunk/src@11721 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/core/SkMatrix.cpp b/core/SkMatrix.cpp
index 3a5ab62..d802e1c 100644
--- a/core/SkMatrix.cpp
+++ b/core/SkMatrix.cpp
@@ -8,6 +8,7 @@
#include "SkMatrix.h"
#include "Sk64.h"
#include "SkFloatBits.h"
+#include "SkOnce.h"
#include "SkScalarCompare.h"
#include "SkString.h"
@@ -1893,13 +1894,14 @@
return SkScalarSqrt(largerRoot);
}
+DEF_SK_ONCE(reset_identity_matrix, SkMatrix* identity) {
+ identity->reset();
+}
+
const SkMatrix& SkMatrix::I() {
+ // If you can use C++11 now, you might consider replacing this with a constexpr constructor.
static SkMatrix gIdentity;
- static bool gOnce;
- if (!gOnce) {
- gIdentity.reset();
- gOnce = true;
- }
+ SK_ONCE(reset_identity_matrix, &gIdentity);
return gIdentity;
}