diff --git a/src/interface.cc b/src/interface.cc index d325c0e4d8..a45804cf52 100644 --- a/src/interface.cc +++ b/src/interface.cc @@ -14,36 +14,33 @@ namespace internal { // --------------------------------------------------------------------------- // Initialization. -struct Interface::ValueCreate { - static void Construct(Interface* ptr) { - ::new (ptr) Interface(VALUE + FROZEN); - } +struct Interface::Cache { + template + struct Create { + static void Construct(Interface* ptr) { ::new (ptr) Interface(flags); } + }; + typedef Create ValueCreate; + typedef Create ConstCreate; + + static base::LazyInstance::type value_interface; + static base::LazyInstance::type const_interface; }; -struct Interface::ConstCreate { - static void Construct(Interface* ptr) { - ::new (ptr) Interface(VALUE + CONST + FROZEN); - } -}; +base::LazyInstance::type + Interface::Cache::value_interface = LAZY_INSTANCE_INITIALIZER; - -namespace { - base::LazyInstance::type value_interface = - LAZY_INSTANCE_INITIALIZER; - - base::LazyInstance::type const_interface = - LAZY_INSTANCE_INITIALIZER; -} +base::LazyInstance::type + Interface::Cache::const_interface = LAZY_INSTANCE_INITIALIZER; Interface* Interface::NewValue() { - return value_interface.Pointer(); // Cached. + return Cache::value_interface.Pointer(); // Cached. } Interface* Interface::NewConst() { - return const_interface.Pointer(); // Cached. + return Cache::const_interface.Pointer(); // Cached. } diff --git a/src/interface.h b/src/interface.h index ae549634c5..19f89ce9a7 100644 --- a/src/interface.h +++ b/src/interface.h @@ -172,8 +172,7 @@ class Interface : public ZoneObject { // --------------------------------------------------------------------------- // Implementation. private: - struct ValueCreate; - struct ConstCreate; + struct Cache; enum Flags { // All flags are monotonic NONE = 0,