Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(393)

Unified Diff: Source/core/css/CSSPrimitiveValue.cpp

Issue 864143006: Remove unsafe DEFINE_STATIC_LOCALs in CSSPrimitiveValue (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/css/CSSPrimitiveValue.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/css/CSSPrimitiveValue.cpp
diff --git a/Source/core/css/CSSPrimitiveValue.cpp b/Source/core/css/CSSPrimitiveValue.cpp
index 7861288d6162c02a3a7200dffaa741209fbb04b8..9a039059b40d629ca97e0f13c7427fa4bcfc95de 100644
--- a/Source/core/css/CSSPrimitiveValue.cpp
+++ b/Source/core/css/CSSPrimitiveValue.cpp
@@ -36,6 +36,8 @@
#include "platform/LayoutUnit.h"
#include "platform/fonts/FontMetrics.h"
#include "wtf/StdLibExtras.h"
+#include "wtf/ThreadSpecific.h"
+#include "wtf/Threading.h"
#include "wtf/text/StringBuffer.h"
#include "wtf/text/StringBuilder.h"
@@ -43,6 +45,8 @@ using namespace WTF;
namespace blink {
+namespace {
+
// Max/min values for CSS, needs to slightly smaller/larger than the true max/min values to allow for rounding without overflowing.
// Subtract two (rather than one) to allow for values to be converted to float and back without exceeding the LayoutUnit::max.
const int maxValueForCssLength = INT_MAX / kFixedPointDenominator - 2;
@@ -139,10 +143,24 @@ StringToUnitTable createStringToUnitTable()
return table;
}
-CSSPrimitiveValue::UnitType CSSPrimitiveValue::fromName(const String& unit)
+StringToUnitTable& unitTable()
{
DEFINE_STATIC_LOCAL(StringToUnitTable, unitTable, (createStringToUnitTable()));
- return unitTable.get(unit.lower());
+ return unitTable;
+}
+
+} // namespace
+
+void CSSPrimitiveValue::initUnitTable()
+{
+ // Make sure we initialize this during blink initialization
+ // to avoid racy static local initialization.
+ unitTable();
+}
+
+CSSPrimitiveValue::UnitType CSSPrimitiveValue::fromName(const String& unit)
+{
+ return unitTable().get(unit.lower());
}
CSSPrimitiveValue::UnitCategory CSSPrimitiveValue::unitCategory(UnitType type)
@@ -198,8 +216,8 @@ bool CSSPrimitiveValue::colorIsDerivedFromElement() const
typedef HashMap<const CSSPrimitiveValue*, String> CSSTextCache;
static CSSTextCache& cssTextCache()
{
- DEFINE_STATIC_LOCAL(CSSTextCache, cache, ());
- return cache;
+ AtomicallyInitializedStaticReference(ThreadSpecific<CSSTextCache>, cache, new ThreadSpecific<CSSTextCache>());
sof 2015/12/02 13:32:41 fwiw, http/tests/misc/client-hints-picture-source-
+ return *cache;
}
CSSPrimitiveValue::UnitType CSSPrimitiveValue::primitiveType() const
« no previous file with comments | « Source/core/css/CSSPrimitiveValue.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698