Bug 1525303 - make LazyLogModule::operator LogModule* inline; r=erahm
authorNathan Froyd <froydnj@mozilla.com>
Tue, 02 Apr 2019 20:35:38 +0000
changeset 467749 88c2a60599669ee7899764812730b90ce98a1450
parent 467748 abf4f3d3b075d1af90654f9f665e2b52455ff46d
child 467750 1b9e5f4b0589a636233affb84666a469a4cc4ef5
push id112658
push useraciure@mozilla.com
push dateThu, 04 Apr 2019 04:41:45 +0000
treeherdermozilla-inbound@a36718c8163e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerserahm
bugs1525303
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1525303 - make LazyLogModule::operator LogModule* inline; r=erahm Testing has determined that doing this has no detrimental size benefit, and a small positive performance impact. Differential Revision: https://phabricator.services.mozilla.com/D25848
xpcom/base/Logging.cpp
xpcom/base/Logging.h
--- a/xpcom/base/Logging.cpp
+++ b/xpcom/base/Logging.cpp
@@ -43,30 +43,16 @@ const uint32_t kInitialModuleCount = 256
 // the given limit.
 //
 // (Note: When this is changed to be >= 10, SandboxBroker::LaunchApp must add
 // another rule to allow logfile.?? be written by content processes.)
 const uint32_t kRotateFilesNumber = 4;
 
 namespace mozilla {
 
-LazyLogModule::operator LogModule*() {
-  // NB: The use of an atomic makes the reading and assignment of mLog
-  //     thread-safe. There is a small chance that mLog will be set more
-  //     than once, but that's okay as it will be set to the same LogModule
-  //     instance each time. Also note LogModule::Get is thread-safe.
-  LogModule* tmp = mLog;
-  if (MOZ_UNLIKELY(!tmp)) {
-    tmp = LogModule::Get(mLogName);
-    mLog = tmp;
-  }
-
-  return tmp;
-}
-
 namespace detail {
 
 void log_print(const LogModule* aModule, LogLevel aLevel, const char* aFmt,
                ...) {
   va_list ap;
   va_start(ap, aFmt);
   aModule->Printv(aLevel, aFmt, ap);
   va_end(ap);
--- a/xpcom/base/Logging.h
+++ b/xpcom/base/Logging.h
@@ -163,17 +163,29 @@ class LogModule {
  *     MOZ_LOG(sLayoutLog, LogLevel::Verbose, ("Entering foo"));
  *   }
  */
 class LazyLogModule final {
  public:
   explicit constexpr LazyLogModule(const char* aLogName)
       : mLogName(aLogName), mLog(nullptr) {}
 
-  operator LogModule*();
+  operator LogModule*() {
+    // NB: The use of an atomic makes the reading and assignment of mLog
+    //     thread-safe. There is a small chance that mLog will be set more
+    //     than once, but that's okay as it will be set to the same LogModule
+    //     instance each time. Also note LogModule::Get is thread-safe.
+    LogModule* tmp = mLog;
+    if (MOZ_UNLIKELY(!tmp)) {
+      tmp = LogModule::Get(mLogName);
+      mLog = tmp;
+    }
+
+    return tmp;
+  }
 
  private:
   const char* const mLogName;
 
   // As for LogModule::mLevel, don't preserve behavior for this atomic when
   // recording/replaying.
   Atomic<LogModule*, ReleaseAcquire, recordreplay::Behavior::DontPreserve> mLog;
 };