]> git.saurik.com Git - apple/javascriptcore.git/blobdiff - runtime/DateInstanceCache.h
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / runtime / DateInstanceCache.h
index 07053062eeabcdf5878ca0b585f94f6b4c04d39f..865ee8ff20b9e85ef3b7ff0446791e9488ee19b4 100644 (file)
 #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(PNaN)
-            , m_gregorianDateTimeUTCCachedForMS(PNaN)
-        {
-        }
-    };
+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 = PNaN;
-        }
-        
-        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;
 
-        std::array<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