Use time literals in WebCore
authorantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 18 Jun 2016 11:46:16 +0000 (11:46 +0000)
committerantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 18 Jun 2016 11:46:16 +0000 (11:46 +0000)
https://bugs.webkit.org/show_bug.cgi?id=158905

Reviewed by Andreas Kling.

std::chrono::milliseconds(1) -> 1ms etc.

* dom/Document.cpp:
(WebCore::Document::minimumLayoutDelay):
(WebCore::Document::elapsedTime):
* fileapi/FileReader.cpp:
(WebCore::FileReader::create):
* inspector/InspectorOverlay.cpp:
(WebCore::InspectorOverlay::showPaintRect):
* loader/CrossOriginPreflightResultCache.cpp:
(WebCore::CrossOriginPreflightResultCache::CrossOriginPreflightResultCache):
* loader/ProgressTracker.cpp:
(WebCore::ProgressTracker::progressStarted):
* loader/cache/CachedResource.cpp:
(WebCore::CachedResource::freshnessLifetime):
* page/ChromeClient.h:
* page/DOMTimer.cpp:
(WebCore::DOMTimer::intervalClampedToMinimum):
(WebCore::DOMTimer::alignedFireTime):
* page/DOMTimer.h:
* page/FrameView.cpp:
(WebCore::FrameView::scrollPositionChanged):
* page/ResourceUsageThread.cpp:
(WebCore::ResourceUsageThread::threadBody):
* page/Settings.cpp:
(WebCore::Settings::Settings):
* page/mac/ServicesOverlayController.mm:
(WebCore::ServicesOverlayController::remainingTimeUntilHighlightShouldBeShown):
* platform/graphics/FontCache.cpp:
(WebCore::FontCache::fontForFamily):
* platform/network/CacheValidation.cpp:
(WebCore::computeCurrentAge):
(WebCore::computeFreshnessLifetimeForHTTPFamily):

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

16 files changed:
Source/WebCore/ChangeLog
Source/WebCore/dom/Document.cpp
Source/WebCore/fileapi/FileReader.cpp
Source/WebCore/inspector/InspectorOverlay.cpp
Source/WebCore/loader/CrossOriginPreflightResultCache.cpp
Source/WebCore/loader/ProgressTracker.cpp
Source/WebCore/loader/cache/CachedResource.cpp
Source/WebCore/page/ChromeClient.h
Source/WebCore/page/DOMTimer.cpp
Source/WebCore/page/DOMTimer.h
Source/WebCore/page/FrameView.cpp
Source/WebCore/page/ResourceUsageThread.cpp
Source/WebCore/page/Settings.cpp
Source/WebCore/page/mac/ServicesOverlayController.mm
Source/WebCore/platform/graphics/FontCache.cpp
Source/WebCore/platform/network/CacheValidation.cpp

index fc4df75..e46d6eb 100644 (file)
@@ -1,3 +1,44 @@
+2016-06-18  Antti Koivisto  <antti@apple.com>
+
+        Use time literals in WebCore
+        https://bugs.webkit.org/show_bug.cgi?id=158905
+
+        Reviewed by Andreas Kling.
+
+        std::chrono::milliseconds(1) -> 1ms etc.
+
+        * dom/Document.cpp:
+        (WebCore::Document::minimumLayoutDelay):
+        (WebCore::Document::elapsedTime):
+        * fileapi/FileReader.cpp:
+        (WebCore::FileReader::create):
+        * inspector/InspectorOverlay.cpp:
+        (WebCore::InspectorOverlay::showPaintRect):
+        * loader/CrossOriginPreflightResultCache.cpp:
+        (WebCore::CrossOriginPreflightResultCache::CrossOriginPreflightResultCache):
+        * loader/ProgressTracker.cpp:
+        (WebCore::ProgressTracker::progressStarted):
+        * loader/cache/CachedResource.cpp:
+        (WebCore::CachedResource::freshnessLifetime):
+        * page/ChromeClient.h:
+        * page/DOMTimer.cpp:
+        (WebCore::DOMTimer::intervalClampedToMinimum):
+        (WebCore::DOMTimer::alignedFireTime):
+        * page/DOMTimer.h:
+        * page/FrameView.cpp:
+        (WebCore::FrameView::scrollPositionChanged):
+        * page/ResourceUsageThread.cpp:
+        (WebCore::ResourceUsageThread::threadBody):
+        * page/Settings.cpp:
+        (WebCore::Settings::Settings):
+        * page/mac/ServicesOverlayController.mm:
+        (WebCore::ServicesOverlayController::remainingTimeUntilHighlightShouldBeShown):
+        * platform/graphics/FontCache.cpp:
+        (WebCore::FontCache::fontForFamily):
+        * platform/network/CacheValidation.cpp:
+        (WebCore::computeCurrentAge):
+        (WebCore::computeFreshnessLifetimeForHTTPFamily):
+
 2016-06-17  Benjamin Poulain  <benjamin@webkit.org>
 
         :indeterminate pseudo-class should match radios whose group has no checked radio
index bb89f60..5bc4387 100644 (file)
@@ -2849,13 +2849,13 @@ bool Document::isLayoutTimerActive()
 std::chrono::milliseconds Document::minimumLayoutDelay()
 {
     if (m_overMinimumLayoutThreshold)
-        return std::chrono::milliseconds(0);
+        return 0ms;
     
-    std::chrono::milliseconds elapsed = elapsedTime();
+    auto elapsed = elapsedTime();
     m_overMinimumLayoutThreshold = elapsed > settings()->layoutInterval();
 
     // We'll want to schedule the timer to fire at the minimum layout threshold.
-    return std::max(std::chrono::milliseconds(0), settings()->layoutInterval() - elapsed);
+    return std::max(0ms, settings()->layoutInterval() - elapsed);
 }
 
 std::chrono::milliseconds Document::elapsedTime() const
index 410de46..bc5f998 100644 (file)
@@ -43,7 +43,7 @@
 
 namespace WebCore {
 
-static const auto progressNotificationInterval = std::chrono::milliseconds(50);
+static const auto progressNotificationInterval = 50ms;
 
 Ref<FileReader> FileReader::create(ScriptExecutionContext& context)
 {
index 224069b..8ce3c10 100644 (file)
@@ -505,7 +505,7 @@ void InspectorOverlay::showPaintRect(const FloatRect& rect)
 
     IntRect rootRect = m_page.mainFrame().view()->contentsToRootView(enclosingIntRect(rect));
 
-    const std::chrono::milliseconds removeDelay = std::chrono::milliseconds(250);
+    const auto removeDelay = 250ms;
 
     std::chrono::steady_clock::time_point removeTime = std::chrono::steady_clock::now() + removeDelay;
     m_paintRects.append(TimeRectPair(removeTime, rootRect));
index 9b277b0..a8f46a2 100644 (file)
@@ -37,8 +37,8 @@
 namespace WebCore {
 
 // These values are at the discretion of the user agent.
-static const auto defaultPreflightCacheTimeout = std::chrono::seconds(5);
-static const auto maxPreflightCacheTimeout = std::chrono::seconds(600); // Should be short enough to minimize the risk of using a poisoned cache after switching to a secure network.
+static const auto defaultPreflightCacheTimeout = 5s;
+static const auto maxPreflightCacheTimeout = 600s; // Should be short enough to minimize the risk of using a poisoned cache after switching to a secure network.
 
 CrossOriginPreflightResultCache::CrossOriginPreflightResultCache()
 {
index d56ca05..09a86b7 100644 (file)
@@ -60,7 +60,7 @@ static const unsigned loadStalledHeartbeatCount = 4;
 // How many bytes are required between heartbeats to consider it progress.
 static const unsigned minumumBytesPerHeartbeatForProgress = 1024;
 
-static const std::chrono::milliseconds progressNotificationTimeInterval = std::chrono::milliseconds(200);
+static const auto progressNotificationTimeInterval = 200ms;
 
 struct ProgressItem {
     WTF_MAKE_NONCOPYABLE(ProgressItem); WTF_MAKE_FAST_ALLOCATED;
@@ -137,7 +137,7 @@ void ProgressTracker::progressStarted(Frame& frame)
         bool isMainFrame = !m_originatingProgressFrame->tree().parent();
         auto elapsedTimeSinceMainLoadComplete = std::chrono::steady_clock::now() - m_mainLoadCompletionTime;
 
-        static const auto subframePartOfMainLoadThreshold = std::chrono::seconds(1);
+        static const auto subframePartOfMainLoadThreshold = 1s;
         m_isMainLoad = isMainFrame || elapsedTimeSinceMainLoadComplete < subframePartOfMainLoadThreshold;
 
         m_client.progressStarted(*m_originatingProgressFrame);
index 5573c4d..21ea814 100644 (file)
@@ -392,7 +392,7 @@ std::chrono::microseconds CachedResource::freshnessLifetime(const ResourceRespon
             // FIXME: We should not cache subresources either, but when we tried this
             // it caused performance and flakiness issues in our test infrastructure.
             if (m_type == MainResource || SchemeRegistry::shouldAlwaysRevalidateURLScheme(protocol))
-                return std::chrono::microseconds::zero();
+                return 0us;
         }
 
         return std::chrono::microseconds::max();
index 7d96809..f59555a 100644 (file)
@@ -239,7 +239,7 @@ public:
     virtual void didPreventDefaultForEvent() = 0;
 #endif
 
-    virtual std::chrono::milliseconds eventThrottlingDelay() { return std::chrono::milliseconds::zero(); };
+    virtual std::chrono::milliseconds eventThrottlingDelay() { return 0ms; };
 
 #if PLATFORM(IOS)
     virtual void didReceiveMobileDocType(bool) = 0;
index ed9d6e6..6600d59 100644 (file)
@@ -52,8 +52,8 @@
 
 namespace WebCore {
 
-static const std::chrono::milliseconds maxIntervalForUserGestureForwarding = std::chrono::milliseconds(1000); // One second matches Gecko.
-static const std::chrono::milliseconds minIntervalForNonUserObservableChangeTimers = std::chrono::milliseconds(1000); // Empirically determined to maximize battery life.
+static const auto maxIntervalForUserGestureForwarding = 1000ms; // One second matches Gecko.
+static const auto minIntervalForNonUserObservableChangeTimers = 1000ms; // Empirically determined to maximize battery life.
 static const int maxTimerNestingLevel = 5;
 
 class DOMTimerFireState {
@@ -406,7 +406,7 @@ std::chrono::milliseconds DOMTimer::intervalClampedToMinimum() const
     ASSERT(scriptExecutionContext());
     ASSERT(m_nestingLevel <= maxTimerNestingLevel);
 
-    auto interval = std::max(std::chrono::milliseconds(1), m_originalInterval);
+    auto interval = std::max(1ms, m_originalInterval);
 
     // Only apply throttling to repeating timers.
     if (m_nestingLevel < maxTimerNestingLevel)
@@ -422,7 +422,7 @@ std::chrono::milliseconds DOMTimer::intervalClampedToMinimum() const
 Optional<std::chrono::milliseconds> DOMTimer::alignedFireTime(std::chrono::milliseconds fireTime) const
 {
     auto alignmentInterval = scriptExecutionContext()->timerAlignmentInterval(m_nestingLevel >= maxTimerNestingLevel);
-    if (alignmentInterval == std::chrono::milliseconds::zero())
+    if (alignmentInterval == 0ms)
         return Nullopt;
     
     static const double randomizedProportion = randomNumber();
index eb0de83..27677e6 100644 (file)
@@ -46,9 +46,9 @@ class DOMTimer final : public RefCounted<DOMTimer>, public SuspendableTimer {
 public:
     virtual ~DOMTimer();
 
-    static std::chrono::milliseconds defaultMinimumInterval() { return std::chrono::milliseconds(4); }
-    static std::chrono::milliseconds defaultAlignmentInterval() { return std::chrono::milliseconds::zero(); }
-    static std::chrono::milliseconds hiddenPageAlignmentInterval() { return std::chrono::milliseconds(1000); }
+    static std::chrono::milliseconds defaultMinimumInterval() { return 4ms; }
+    static std::chrono::milliseconds defaultAlignmentInterval() { return 0ms; }
+    static std::chrono::milliseconds hiddenPageAlignmentInterval() { return 1000ms; }
 
     // Creates a new timer owned by specified ScriptExecutionContext, starts it
     // and returns its Id.
index 47e4d55..106aebf 100644 (file)
@@ -2222,9 +2222,9 @@ void FrameView::scrollOffsetChangedViaPlatformWidgetImpl(const ScrollOffset& old
 void FrameView::scrollPositionChanged(const ScrollPosition& oldPosition, const ScrollPosition& newPosition)
 {
     Page* page = frame().page();
-    auto throttlingDelay = page ? page->chrome().client().eventThrottlingDelay() : std::chrono::milliseconds::zero();
+    auto throttlingDelay = page ? page->chrome().client().eventThrottlingDelay() : 0ms;
 
-    if (throttlingDelay == std::chrono::milliseconds::zero()) {
+    if (throttlingDelay == 0ms) {
         m_delayedScrollEventTimer.stop();
         sendScrollEvent();
     } else if (!m_delayedScrollEventTimer.isActive())
index ef2a525..f93e516 100644 (file)
@@ -119,8 +119,8 @@ NO_RETURN void ResourceUsageThread::threadBody()
         platformThreadBody(m_vm, data);
         notifyObservers(WTFMove(data));
 
-        auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - start);
-        auto difference = std::chrono::milliseconds(500) - duration;
+        auto duration = std::chrono::system_clock::now() - start;
+        auto difference = 500ms - duration;
         std::this_thread::sleep_for(difference);
     }
 }
index 99333fa..c96a8eb 100644 (file)
@@ -175,7 +175,7 @@ static const bool defaultSelectTrailingWhitespaceEnabled = false;
 // This amount of time must have elapsed before we will even consider scheduling a layout without a delay.
 // FIXME: For faster machines this value can really be lowered to 200. 250 is adequate, but a little high
 // for dual G5s. :)
-static const auto layoutScheduleThreshold = std::chrono::milliseconds(250);
+static const auto layoutScheduleThreshold = 250ms;
 
 Settings::Settings(Page* page)
     : m_page(nullptr)
index b167ce2..2f871ba 100644 (file)
@@ -436,7 +436,7 @@ bool ServicesOverlayController::mouseIsOverHighlight(Highlight& highlight, bool&
 std::chrono::milliseconds ServicesOverlayController::remainingTimeUntilHighlightShouldBeShown(Highlight* highlight) const
 {
     if (!highlight)
-        return std::chrono::milliseconds::zero();
+        return 0ms;
 
     auto minimumTimeUntilHighlightShouldBeShown = 200ms;
     Page* page = m_mainFrame.page();
index 30eff7f..ce5f088 100644 (file)
@@ -327,7 +327,7 @@ const unsigned cTargetUnderMemoryPressureInactiveFontData = 30;
 RefPtr<Font> FontCache::fontForFamily(const FontDescription& fontDescription, const AtomicString& family, const FontFeatureSettings* fontFaceFeatures, const FontVariantSettings* fontFaceVariantSettings, bool checkingAlternateName)
 {
     if (!m_purgeTimer.isActive())
-        m_purgeTimer.startOneShot(std::chrono::milliseconds::zero());
+        m_purgeTimer.startOneShot(0ms);
 
     FontPlatformData* platformData = getCachedFontPlatformData(fontDescription, family, fontFaceFeatures, fontFaceVariantSettings, checkingAlternateName);
     if (!platformData)
index 9b9f900..08691b0 100644 (file)
@@ -103,8 +103,8 @@ std::chrono::microseconds computeCurrentAge(const ResourceResponse& response, st
     // http://tools.ietf.org/html/rfc7234#section-4.2.3
     // No compensation for latency as that is not terribly important in practice.
     auto dateValue = response.date();
-    auto apparentAge = dateValue ? std::max(microseconds::zero(), duration_cast<microseconds>(responseTime - dateValue.value())) : microseconds::zero();
-    auto ageValue = response.age().valueOr(microseconds::zero());
+    auto apparentAge = dateValue ? std::max(0us, duration_cast<microseconds>(responseTime - *dateValue)) : 0us;
+    auto ageValue = response.age().valueOr(0us);
     auto correctedInitialAge = std::max(apparentAge, ageValue);
     auto residentTime = duration_cast<microseconds>(system_clock::now() - responseTime);
     return correctedInitialAge + residentTime;
@@ -119,26 +119,25 @@ std::chrono::microseconds computeFreshnessLifetimeForHTTPFamily(const ResourceRe
     // http://tools.ietf.org/html/rfc7234#section-4.2.1
     auto maxAge = response.cacheControlMaxAge();
     if (maxAge)
-        return maxAge.value();
-    auto expires = response.expires();
+        return *maxAge;
+
     auto date = response.date();
-    auto dateValue = date ? date.value() : responseTime;
-    if (expires)
-        return duration_cast<microseconds>(expires.value() - dateValue);
+    auto effectiveDate = date.valueOr(responseTime);
+    if (auto expires = response.expires())
+        return duration_cast<microseconds>(*expires - effectiveDate);
 
     // Implicit lifetime.
     switch (response.httpStatusCode()) {
     case 301: // Moved Permanently
     case 410: // Gone
         // These are semantically permanent and so get long implicit lifetime.
-        return hours(365 * 24);
+        return 365 * 24h;
     default:
         // Heuristic Freshness:
         // http://tools.ietf.org/html/rfc7234#section-4.2.2
-        auto lastModified = response.lastModified();
-        if (lastModified)
-            return duration_cast<microseconds>((dateValue - lastModified.value()) * 0.1);
-        return microseconds::zero();
+        if (auto lastModified = response.lastModified())
+            return duration_cast<microseconds>((effectiveDate - *lastModified) * 0.1);
+        return 0us;
     }
 }