Purge PassRefPtr in JavaScriptCore
[WebKit-https.git] / Source / JavaScriptCore / runtime / DateInstanceCache.h
index cdd12cf..6ebbb0d 100644 (file)
 #ifndef DateInstanceCache_h
 #define DateInstanceCache_h
 
-#include <wtf/DateMath.h>
-#include <wtf/FixedArray.h>
+#include "JSCJSValue.h"
+#include "JSDateMath.h"
+#include <array>
 #include <wtf/HashFunctions.h>
 #include <wtf/PassRefPtr.h>
 #include <wtf/RefCounted.h>
 
 namespace JSC {
 
-    class DateInstanceData : public RefCounted<DateInstanceData> {
-    public:
-        static PassRefPtr<DateInstanceData> create() { return adoptRef(new DateInstanceData); }
-
-        double m_gregorianDateTimeCachedForMS;
-        GregorianDateTime m_cachedGregorianDateTime;
-        double m_gregorianDateTimeUTCCachedForMS;
-        GregorianDateTime m_cachedGregorianDateTimeUTC;
-
-    private:
-        DateInstanceData()
-            : m_gregorianDateTimeCachedForMS(std::numeric_limits<double>::quiet_NaN())
-            , m_gregorianDateTimeUTCCachedForMS(std::numeric_limits<double>::quiet_NaN())
-        {
-        }
-    };
+class DateInstanceData : public RefCounted<DateInstanceData> {
+public:
+    static Ref<DateInstanceData> create() { return adoptRef(*new DateInstanceData); }
 
-    class DateInstanceCache {
-    public:
-        DateInstanceCache()
-        {
-            reset();
-        }
-        
-        void reset()
-        {
-            for (size_t i = 0; i < cacheSize; ++i)
-                m_cache[i].key = std::numeric_limits<double>::quiet_NaN();
-        }
-        
-        DateInstanceData* add(double d)
-        {
-            CacheEntry& entry = lookup(d);
-            if (d == entry.key)
-                return entry.value.get();
-
-            entry.key = d;
-            entry.value = DateInstanceData::create();
-            return entry.value.get();
-        }
+    double m_gregorianDateTimeCachedForMS;
+    GregorianDateTime m_cachedGregorianDateTime;
+    double m_gregorianDateTimeUTCCachedForMS;
+    GregorianDateTime m_cachedGregorianDateTimeUTC;
+
+private:
+    DateInstanceData()
+        : m_gregorianDateTimeCachedForMS(PNaN)
+        , m_gregorianDateTimeUTCCachedForMS(PNaN)
+    {
+    }
+};
+
+class DateInstanceCache {
+public:
+    DateInstanceCache()
+    {
+        reset();
+    }
 
-    private:
-        static const size_t cacheSize = 16;
+    void reset()
+    {
+        for (size_t i = 0; i < cacheSize; ++i)
+            m_cache[i].key = PNaN;
+    }
 
-        struct CacheEntry {
-            double key;
-            RefPtr<DateInstanceData> value;
-        };
+    DateInstanceData* add(double d)
+    {
+        CacheEntry& entry = lookup(d);
+        if (d == entry.key)
+            return entry.value.get();
+
+        entry.key = d;
+        entry.value = DateInstanceData::create();
+        return entry.value.get();
+    }
 
-        CacheEntry& lookup(double d) { return m_cache[WTF::FloatHash<double>::hash(d) & (cacheSize - 1)]; }
+private:
+    static const size_t cacheSize = 16;
 
-        FixedArray<CacheEntry, cacheSize> m_cache;
+    struct CacheEntry {
+        double key;
+        RefPtr<DateInstanceData> value;
     };
 
+    CacheEntry& lookup(double d) { return m_cache[WTF::FloatHash<double>::hash(d) & (cacheSize - 1)]; }
+
+    std::array<CacheEntry, cacheSize> m_cache;
+};
+
 } // namespace JSC
 
 #endif // DateInstanceCache_h