clang-tidy: Fix unnecessary object copy in CPUMonitor::setCPULimit()
authorddkilzer@apple.com <ddkilzer@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 18 Dec 2018 04:09:50 +0000 (04:09 +0000)
committerddkilzer@apple.com <ddkilzer@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 18 Dec 2018 04:09:50 +0000 (04:09 +0000)
<https://webkit.org/b/192707>
<rdar://problem/46734926>

Reviewed by Daniel Bates.

Source/WebCore:

* platform/CPUMonitor.cpp:
(WebCore::CPUMonitor::setCPULimit):
* platform/CPUMonitor.h:
(WebCore::CPUMonitor::setCPULimit):
- Change parameter to const reference to fix unnecessary copies.

Source/WebKit:

* WebProcess/cocoa/WebProcessCocoa.mm:
(WebKit::WebProcess::updateCPUMonitorState):
- Pass m_cpuLimit directly since getting its value causes an
  identical std::optional<double> to be created unnecessarily.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@239315 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/CPUMonitor.cpp
Source/WebCore/platform/CPUMonitor.h
Source/WebKit/ChangeLog
Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm

index 9134293..4232fa2 100644 (file)
@@ -1,3 +1,17 @@
+2018-12-17  David Kilzer  <ddkilzer@apple.com>
+
+        clang-tidy: Fix unnecessary object copy in CPUMonitor::setCPULimit()
+        <https://webkit.org/b/192707>
+        <rdar://problem/46734926>
+
+        Reviewed by Daniel Bates.
+
+        * platform/CPUMonitor.cpp:
+        (WebCore::CPUMonitor::setCPULimit):
+        * platform/CPUMonitor.h:
+        (WebCore::CPUMonitor::setCPULimit):
+        - Change parameter to const reference to fix unnecessary copies.
+
 2018-12-17  Ryosuke Niwa  <rniwa@webkit.org>
 
         offsetLeft and offsetParent should adjust across shadow boundaries
index 5faaf66..e275673 100644 (file)
@@ -35,7 +35,7 @@ CPUMonitor::CPUMonitor(Seconds checkInterval, ExceededCPULimitHandler&& exceeded
 {
 }
 
-void CPUMonitor::setCPULimit(std::optional<double> cpuLimit)
+void CPUMonitor::setCPULimit(const std::optional<double>& cpuLimit)
 {
     if (m_cpuLimit == cpuLimit)
         return;
index d4ddb77..6ec486f 100644 (file)
@@ -37,7 +37,7 @@ public:
     using ExceededCPULimitHandler = WTF::Function<void(double)>;
     WEBCORE_EXPORT CPUMonitor(Seconds checkInterval, ExceededCPULimitHandler&&);
 
-    WEBCORE_EXPORT void setCPULimit(std::optional<double>);
+    WEBCORE_EXPORT void setCPULimit(const std::optional<double>&);
 
 private:
     void timerFired();
index dbb9e51..f09df14 100644 (file)
@@ -1,3 +1,16 @@
+2018-12-17  David Kilzer  <ddkilzer@apple.com>
+
+        clang-tidy: Fix unnecessary object copy in CPUMonitor::setCPULimit()
+        <https://webkit.org/b/192707>
+        <rdar://problem/46734926>
+
+        Reviewed by Daniel Bates.
+
+        * WebProcess/cocoa/WebProcessCocoa.mm:
+        (WebKit::WebProcess::updateCPUMonitorState):
+        - Pass m_cpuLimit directly since getting its value causes an
+          identical std::optional<double> to be created unnecessarily.
+
 2018-12-17  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         [iOS] Focusing a large editable element always scrolls to the top of the element
index 2f2496b..95471bd 100644 (file)
@@ -561,7 +561,7 @@ void WebProcess::updateCPUMonitorState(CPUMonitorUpdateReason reason)
         // not want to report that a process has exceeded its background CPU limit even though most of the CPU time was used while the process was visible.
         m_cpuMonitor->setCPULimit(std::nullopt);
     }
-    m_cpuMonitor->setCPULimit(m_cpuLimit.value());
+    m_cpuMonitor->setCPULimit(m_cpuLimit);
 #else
     UNUSED_PARAM(reason);
 #endif