]> git.saurik.com Git - apple/javascriptcore.git/blobdiff - wtf/ByteArray.h
JavaScriptCore-903.tar.gz
[apple/javascriptcore.git] / wtf / ByteArray.h
index 865c30ec231c70c3bb861ca8a00f5433220446da..bdec630b4d186201e070227860fd1e3658389f08 100644 (file)
 #ifndef ByteArray_h
 #define ByteArray_h
 
-#include "wtf/PassRefPtr.h"
-#include "wtf/RefCounted.h"
+#include <limits.h>
+#include <wtf/PassRefPtr.h>
+#include <wtf/Platform.h>
+#include <wtf/RefCounted.h>
 
 namespace WTF {
     class ByteArray : public RefCountedBase {
@@ -45,6 +47,13 @@ namespace WTF {
             m_data[index] = static_cast<unsigned char>(value + 0.5);
         }
 
+        void set(unsigned index, unsigned char value)
+        {
+            if (index >= m_size)
+                return;
+            m_data[index] = value;
+        }
+
         bool get(unsigned index, unsigned char& result) const
         {
             if (index >= m_size)
@@ -53,6 +62,12 @@ namespace WTF {
             return true;
         }
 
+        unsigned char get(unsigned index) const
+        {
+            ASSERT(index < m_size);
+            return m_data[index];
+        }
+
         unsigned char* data() { return m_data; }
 
         void deref()
@@ -69,13 +84,21 @@ namespace WTF {
 
     private:
         ByteArray(size_t size)
-            : RefCountedBase(1)
-            , m_size(size)
+            : m_size(size)
         {
         }
         size_t m_size;
-        unsigned char m_data[sizeof(size_t)];
+// MSVC can't handle correctly unsized array.
+// warning C4200: nonstandard extension used : zero-sized array in struct/union
+// Cannot generate copy-ctor or copy-assignment operator when UDT contains a zero-sized array
+#if COMPILER(MSVC)
+        unsigned char m_data[INT_MAX];
+#else
+        unsigned char m_data[];
+#endif
     };
-}
+} // namespace WTF
+
+using WTF::ByteArray;
 
 #endif