[SCM] WebKit Debian packaging branch, webkit-1.2, updated. upstream/1.1.90-6072-g9a69373

darin at apple.com darin at apple.com
Thu Apr 8 02:24:06 UTC 2010


The following commit has been merged in the webkit-1.2 branch:
commit 17041057d2a36d11e90d98568646d3e1aa3263bc
Author: darin at apple.com <darin at apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Tue Mar 16 20:46:02 2010 +0000

    Added arrayLength function and used it instead of hand-written code.
    
    Reviewed by Sam Weinig.
    
    * JavaScriptCore.xcodeproj/project.pbxproj:
    Removed PtrAndFlags.h. The file was removed long ago.
    
    * interpreter/Interpreter.cpp:
    (JSC::Interpreter::privateExecute): Use arrayLength.
    
    * runtime/Collector.h:
    (JSC::CollectorBitmap::count): Remove WTF:: prefix from use
    of bitCount. In WTF we inject things into the global namespace
    and this is no exception.
    
    * runtime/DatePrototype.cpp:
    (JSC::formatLocaleDate): Use arrayLength.
    
    * runtime/JSFunction.h:
    (JSC::JSFunction::nativeFunction): Remove WTF:: prefix as above.
    (JSC::JSFunction::scopeChain): Ditto.
    (JSC::JSFunction::setScopeChain): Ditto.
    (JSC::JSFunction::setNativeFunction): Ditto.
    
    * runtime/JSGlobalObject.cpp:
    (JSC::JSGlobalObject::reset): Use arrayLength.
    
    * runtime/JSImmediate.h:
    (JSC::reinterpretDoubleToIntptr): Remove WTF:: prefix as above.
    (JSC::reinterpretIntptrToDouble): Ditto.
    
    * runtime/JSONObject.cpp:
    (JSC::Stringifier::appendQuotedString): Use arrayLength.
    (JSC::Stringifier::toJSON): Ditto.
    (JSC::Stringifier::appendStringifiedValue): Ditto.
    * runtime/SmallStrings.cpp:
    (JSC::SmallStrings::SmallStrings): Ditto.
    
    * runtime/UString.cpp:
    (JSC::UString::from): Use arrayLength.
    
    * wtf/StdLibExtras.h:
    (WTF::bitwise_cast): Marked this inline!
    (WTF::arrayLength): Added function template (actually written by Sam).
    Added using declarations for public things in WTF namespace defined
    in this file.
    
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@56081 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/JavaScriptCore/ChangeLog b/JavaScriptCore/ChangeLog
index 5841710..bd17f85 100644
--- a/JavaScriptCore/ChangeLog
+++ b/JavaScriptCore/ChangeLog
@@ -1,3 +1,52 @@
+2010-03-16  Darin Adler  <darin at apple.com>
+
+        Reviewed by Sam Weinig.
+
+        Added arrayLength function and used it instead of hand-written code.
+
+        * JavaScriptCore.xcodeproj/project.pbxproj:
+        Removed PtrAndFlags.h. The file was removed long ago.
+
+        * interpreter/Interpreter.cpp:
+        (JSC::Interpreter::privateExecute): Use arrayLength.
+
+        * runtime/Collector.h:
+        (JSC::CollectorBitmap::count): Remove WTF:: prefix from use
+        of bitCount. In WTF we inject things into the global namespace
+        and this is no exception.
+
+        * runtime/DatePrototype.cpp:
+        (JSC::formatLocaleDate): Use arrayLength.
+
+        * runtime/JSFunction.h:
+        (JSC::JSFunction::nativeFunction): Remove WTF:: prefix as above.
+        (JSC::JSFunction::scopeChain): Ditto.
+        (JSC::JSFunction::setScopeChain): Ditto.
+        (JSC::JSFunction::setNativeFunction): Ditto.
+
+        * runtime/JSGlobalObject.cpp:
+        (JSC::JSGlobalObject::reset): Use arrayLength.
+
+        * runtime/JSImmediate.h:
+        (JSC::reinterpretDoubleToIntptr): Remove WTF:: prefix as above.
+        (JSC::reinterpretIntptrToDouble): Ditto.
+
+        * runtime/JSONObject.cpp:
+        (JSC::Stringifier::appendQuotedString): Use arrayLength.
+        (JSC::Stringifier::toJSON): Ditto.
+        (JSC::Stringifier::appendStringifiedValue): Ditto.
+        * runtime/SmallStrings.cpp:
+        (JSC::SmallStrings::SmallStrings): Ditto.
+
+        * runtime/UString.cpp:
+        (JSC::UString::from): Use arrayLength.
+
+        * wtf/StdLibExtras.h:
+        (WTF::bitwise_cast): Marked this inline!
+        (WTF::arrayLength): Added function template (actually written by Sam).
+        Added using declarations for public things in WTF namespace defined
+        in this file.
+
 2010-03-16  Zoltan Horvath  <zoltan at webkit.org>
 
         Reviewed by Darin Adler.
diff --git a/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj b/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
index a0d4556..217eddc 100644
--- a/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
+++ b/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
@@ -551,7 +551,6 @@
 		088FA5B90EF76D4300578E6F /* RandomNumber.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RandomNumber.cpp; sourceTree = "<group>"; };
 		088FA5BA0EF76D4300578E6F /* RandomNumber.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RandomNumber.h; sourceTree = "<group>"; };
 		08E279E80EF83B10007DB523 /* RandomNumberSeed.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RandomNumberSeed.h; sourceTree = "<group>"; };
-		0B1F921B0F17502D0036468E /* PtrAndFlags.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PtrAndFlags.h; sourceTree = "<group>"; };
 		0B330C260F38C62300692DE3 /* TypeTraits.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TypeTraits.cpp; sourceTree = "<group>"; };
 		0B4D7E620F319AC800AD7E58 /* TypeTraits.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TypeTraits.h; sourceTree = "<group>"; };
 		0BDFFAD10FC616EC00D69EF4 /* OwnFastMallocPtr.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OwnFastMallocPtr.h; sourceTree = "<group>"; };
@@ -1333,7 +1332,6 @@
 				6580F795094070560082C219 /* PassRefPtr.h */,
 				65D6D87E09B5A32E0002E4D7 /* Platform.h */,
 				A7D649A91015224E009B2E1B /* PossiblyNull.h */,
-				0B1F921B0F17502D0036468E /* PtrAndFlags.h */,
 				088FA5B90EF76D4300578E6F /* RandomNumber.cpp */,
 				088FA5BA0EF76D4300578E6F /* RandomNumber.h */,
 				08E279E80EF83B10007DB523 /* RandomNumberSeed.h */,
diff --git a/JavaScriptCore/interpreter/Interpreter.cpp b/JavaScriptCore/interpreter/Interpreter.cpp
index 69d2564..98e6ee0 100644
--- a/JavaScriptCore/interpreter/Interpreter.cpp
+++ b/JavaScriptCore/interpreter/Interpreter.cpp
@@ -1134,7 +1134,7 @@ JSValue Interpreter::privateExecute(ExecutionFlag flag, RegisterFile* registerFi
         #if HAVE(COMPUTED_GOTO)
             #define LIST_OPCODE_LABEL(id, length) &&id,
                 static Opcode labels[] = { FOR_EACH_OPCODE_ID(LIST_OPCODE_LABEL) };
-                for (size_t i = 0; i < sizeof(labels) / sizeof(Opcode); ++i)
+                for (size_t i = 0; i < arrayLength(labels); ++i)
                     m_opcodeTable[i] = labels[i];
             #undef LIST_OPCODE_LABEL
         #endif // HAVE(COMPUTED_GOTO)
diff --git a/JavaScriptCore/runtime/Collector.h b/JavaScriptCore/runtime/Collector.h
index 82aa8a1..3e323d8 100644
--- a/JavaScriptCore/runtime/Collector.h
+++ b/JavaScriptCore/runtime/Collector.h
@@ -216,7 +216,7 @@ namespace JSC {
                     ++result;
             }
             for (size_t i = startCell >> 5; i < BITMAP_WORDS; ++i)
-                result += WTF::bitCount(bits[i]);
+                result += bitCount(bits[i]);
             return result;
         }
         size_t isEmpty() // Much more efficient than testing count() == 0.
diff --git a/JavaScriptCore/runtime/DatePrototype.cpp b/JavaScriptCore/runtime/DatePrototype.cpp
index 25b0ac4..6e39f2d 100644
--- a/JavaScriptCore/runtime/DatePrototype.cpp
+++ b/JavaScriptCore/runtime/DatePrototype.cpp
@@ -180,7 +180,7 @@ static JSCell* formatLocaleDate(ExecState* exec, DateInstance*, double timeInMil
     // We truncate the string returned from CFDateFormatter if it's absurdly long (> 200 characters).
     // That's not great error handling, but it just won't happen so it doesn't matter.
     UChar buffer[200];
-    const size_t bufferLength = sizeof(buffer) / sizeof(buffer[0]);
+    const size_t bufferLength = arrayLength(buffer);
     size_t length = CFStringGetLength(string);
     ASSERT(length <= bufferLength);
     if (length > bufferLength)
diff --git a/JavaScriptCore/runtime/JSFunction.h b/JavaScriptCore/runtime/JSFunction.h
index afa24a8..1c0af37 100644
--- a/JavaScriptCore/runtime/JSFunction.h
+++ b/JavaScriptCore/runtime/JSFunction.h
@@ -66,7 +66,7 @@ namespace JSC {
 
         NativeFunction nativeFunction()
         {
-            return *WTF::bitwise_cast<NativeFunction*>(m_data);
+            return *bitwise_cast<NativeFunction*>(m_data);
         }
 
         virtual ConstructType getConstructData(ConstructData&);
@@ -98,7 +98,7 @@ namespace JSC {
         ScopeChain& scopeChain()
         {
             ASSERT(!isHostFunctionNonInline());
-            return *WTF::bitwise_cast<ScopeChain*>(m_data);
+            return *bitwise_cast<ScopeChain*>(m_data);
         }
         void clearScopeChain()
         {
@@ -113,11 +113,11 @@ namespace JSC {
         void setScopeChain(const ScopeChain& sc)
         {
             ASSERT(!isHostFunctionNonInline());
-            *WTF::bitwise_cast<ScopeChain*>(m_data) = sc;
+            *bitwise_cast<ScopeChain*>(m_data) = sc;
         }
         void setNativeFunction(NativeFunction func)
         {
-            *WTF::bitwise_cast<NativeFunction*>(m_data) = func;
+            *bitwise_cast<NativeFunction*>(m_data) = func;
         }
         unsigned char m_data[sizeof(void*)];
     };
diff --git a/JavaScriptCore/runtime/JSGlobalObject.cpp b/JavaScriptCore/runtime/JSGlobalObject.cpp
index 4bf0a69..2d64024 100644
--- a/JavaScriptCore/runtime/JSGlobalObject.cpp
+++ b/JavaScriptCore/runtime/JSGlobalObject.cpp
@@ -325,7 +325,7 @@ void JSGlobalObject::reset(JSValue prototype)
         GlobalPropertyInfo(Identifier(exec, "JSON"), new (exec) JSONObject(JSONObject::createStructure(d()->objectPrototype)), DontEnum | DontDelete)
     };
 
-    addStaticGlobals(staticGlobals, sizeof(staticGlobals) / sizeof(GlobalPropertyInfo));
+    addStaticGlobals(staticGlobals, arrayLength(staticGlobals));
 
     // Set global functions.
 
diff --git a/JavaScriptCore/runtime/JSImmediate.h b/JavaScriptCore/runtime/JSImmediate.h
index 0f54f60..6f25d38 100644
--- a/JavaScriptCore/runtime/JSImmediate.h
+++ b/JavaScriptCore/runtime/JSImmediate.h
@@ -47,12 +47,12 @@ namespace JSC {
 #if USE(JSVALUE64)
     inline intptr_t reinterpretDoubleToIntptr(double value)
     {
-        return WTF::bitwise_cast<intptr_t>(value);
+        return bitwise_cast<intptr_t>(value);
     }
 
     inline double reinterpretIntptrToDouble(intptr_t value)
     {
-        return WTF::bitwise_cast<double>(value);
+        return bitwise_cast<double>(value);
     }
 #endif
 
diff --git a/JavaScriptCore/runtime/JSONObject.cpp b/JavaScriptCore/runtime/JSONObject.cpp
index d69a8da..7e53ceb 100644
--- a/JavaScriptCore/runtime/JSONObject.cpp
+++ b/JavaScriptCore/runtime/JSONObject.cpp
@@ -321,7 +321,7 @@ void Stringifier::appendQuotedString(StringBuilder& builder, const UString& valu
                 static const char hexDigits[] = "0123456789abcdef";
                 UChar ch = data[i];
                 UChar hex[] = { '\\', 'u', hexDigits[(ch >> 12) & 0xF], hexDigits[(ch >> 8) & 0xF], hexDigits[(ch >> 4) & 0xF], hexDigits[ch & 0xF] };
-                builder.append(hex, sizeof(hex) / sizeof(UChar));
+                builder.append(hex, arrayLength(hex));
                 break;
         }
     }
@@ -349,7 +349,7 @@ inline JSValue Stringifier::toJSON(JSValue value, const PropertyNameForFunctionC
         return value;
 
     JSValue list[] = { propertyName.value(m_exec) };
-    ArgList args(list, sizeof(list) / sizeof(JSValue));
+    ArgList args(list, arrayLength(list));
     return call(m_exec, object, callType, callData, value, args);
 }
 
@@ -363,7 +363,7 @@ Stringifier::StringifyResult Stringifier::appendStringifiedValue(StringBuilder&
     // Call the replacer function.
     if (m_replacerCallType != CallTypeNone) {
         JSValue list[] = { propertyName.value(m_exec), value };
-        ArgList args(list, sizeof(list) / sizeof(JSValue));
+        ArgList args(list, arrayLength(list));
         value = call(m_exec, m_replacer, m_replacerCallType, m_replacerCallData, holder, args);
         if (m_exec->hadException())
             return StringifyFailed;
diff --git a/JavaScriptCore/runtime/SmallStrings.cpp b/JavaScriptCore/runtime/SmallStrings.cpp
index 78bd4e4..96b8ab3 100644
--- a/JavaScriptCore/runtime/SmallStrings.cpp
+++ b/JavaScriptCore/runtime/SmallStrings.cpp
@@ -61,7 +61,7 @@ SmallStringsStorage::SmallStringsStorage()
 
 SmallStrings::SmallStrings()
 {
-    COMPILE_ASSERT(numCharactersToStore == sizeof(m_singleCharacterStrings) / sizeof(m_singleCharacterStrings[0]), IsNumCharactersConstInSyncWithClassUsage);
+    COMPILE_ASSERT(numCharactersToStore == arrayLength(m_singleCharacterStrings), IsNumCharactersConstInSyncWithClassUsage);
     clear();
 }
 
diff --git a/JavaScriptCore/runtime/UString.cpp b/JavaScriptCore/runtime/UString.cpp
index 60b6278..8db72c7 100644
--- a/JavaScriptCore/runtime/UString.cpp
+++ b/JavaScriptCore/runtime/UString.cpp
@@ -178,7 +178,7 @@ UString::UString(const UChar* c, unsigned length)
 UString UString::from(int i)
 {
     UChar buf[1 + sizeof(i) * 3];
-    UChar* end = buf + sizeof(buf) / sizeof(UChar);
+    UChar* end = buf + arrayLength(buf);
     UChar* p = end;
 
     if (i == 0)
@@ -207,7 +207,7 @@ UString UString::from(int i)
 UString UString::from(long long i)
 {
     UChar buf[1 + sizeof(i) * 3];
-    UChar* end = buf + sizeof(buf) / sizeof(UChar);
+    UChar* end = buf + arrayLength(buf);
     UChar* p = end;
 
     if (i == 0)
@@ -240,7 +240,7 @@ UString UString::from(long long i)
 UString UString::from(unsigned int u)
 {
     UChar buf[sizeof(u) * 3];
-    UChar* end = buf + sizeof(buf) / sizeof(UChar);
+    UChar* end = buf + arrayLength(buf);
     UChar* p = end;
 
     if (u == 0)
@@ -258,7 +258,7 @@ UString UString::from(unsigned int u)
 UString UString::from(long l)
 {
     UChar buf[1 + sizeof(l) * 3];
-    UChar* end = buf + sizeof(buf) / sizeof(UChar);
+    UChar* end = buf + arrayLength(buf);
     UChar* p = end;
 
     if (l == 0)
diff --git a/JavaScriptCore/wtf/StdLibExtras.h b/JavaScriptCore/wtf/StdLibExtras.h
index 96a929c..604e89c 100644
--- a/JavaScriptCore/wtf/StdLibExtras.h
+++ b/JavaScriptCore/wtf/StdLibExtras.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008 Apple Inc. All Rights Reserved.
+ * Copyright (C) 2008, 2010 Apple Inc. All Rights Reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -26,6 +26,7 @@
 #ifndef WTF_StdLibExtras_h
 #define WTF_StdLibExtras_h
 
+#include <stdlib.h>
 #include <wtf/Assertions.h>
 
 // Use these to declare and define a static local variable (static T;) so that
@@ -53,11 +54,9 @@
 
 namespace WTF {
 
-    /*
-     * C++'s idea of a reinterpret_cast lacks sufficient cojones.
-     */
+    // C++'s idea of a reinterpret_cast lacks sufficient cojones.
     template<typename TO, typename FROM>
-    TO bitwise_cast(FROM from)
+    inline TO bitwise_cast(FROM from)
     {
         COMPILE_ASSERT(sizeof(TO) == sizeof(FROM), WTF_bitwise_cast_sizeof_casted_types_is_equal);
         union {
@@ -76,6 +75,17 @@ namespace WTF {
         return (((bits + (bits >> 4)) & 0xF0F0F0F) * 0x1010101) >> 24;
     }
 
+    // Returns the length of an array. Use instead of macros such as ARRAYSIZE.
+    template<class ElementType, size_t length>
+    inline size_t arrayLength(ElementType (&)[length])
+    {
+        return length;
+    }
+
 } // namespace WTF
 
+using WTF::arrayLength;
+using WTF::bitCount;
+using WTF::bitwise_cast;
+
 #endif

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list