Title: [124922] trunk/Source
Revision
124922
Author
[email protected]
Date
2012-08-07 14:46:07 -0700 (Tue, 07 Aug 2012)

Log Message

Use the initialization from literal for JSC's Identifiers
https://bugs.webkit.org/show_bug.cgi?id=93193

Reviewed by Geoffrey Garen.

Source/_javascript_Core: 

This patches modify Identifier ot take advantage of the new initialization from literal.

In addition to the memory savings (~600bytes per instance), this gives us a 2% speed
improvement on CommonIdentifiers on average.

* runtime/CommonIdentifiers.cpp:
(JSC::CommonIdentifiers::CommonIdentifiers):
Null and empty strings are forbidden for literal initialization. Use the most efficient constructors
instead of a literal.

* runtime/Identifier.cpp:
(IdentifierASCIIStringTranslator):
Rename IdentifierCStringTranslator to IdentifierASCIIStringTranslator to make the text encoding
explicit.
(JSC::IdentifierASCIIStringTranslator::hash):
(JSC::IdentifierASCIIStringTranslator::equal):
(JSC::IdentifierASCIIStringTranslator::translate): Use the fast initialization from literal.
(JSC::Identifier::add):
* runtime/Identifier.h:
(JSC::Identifier::Identifier):

Source/WTF: 

* wtf/text/StringImpl.h: Update the names for the HashTranslator used by Identifier.

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (124921 => 124922)


--- trunk/Source/_javascript_Core/ChangeLog	2012-08-07 21:42:05 UTC (rev 124921)
+++ trunk/Source/_javascript_Core/ChangeLog	2012-08-07 21:46:07 UTC (rev 124922)
@@ -1,3 +1,31 @@
+2012-08-07  Benjamin Poulain  <[email protected]>
+
+        Use the initialization from literal for JSC's Identifiers
+        https://bugs.webkit.org/show_bug.cgi?id=93193
+
+        Reviewed by Geoffrey Garen.
+
+        This patches modify Identifier ot take advantage of the new initialization from literal.
+
+        In addition to the memory savings (~600bytes per instance), this gives us a 2% speed
+        improvement on CommonIdentifiers on average.
+
+        * runtime/CommonIdentifiers.cpp:
+        (JSC::CommonIdentifiers::CommonIdentifiers):
+        Null and empty strings are forbidden for literal initialization. Use the most efficient constructors
+        instead of a literal.
+
+        * runtime/Identifier.cpp:
+        (IdentifierASCIIStringTranslator):
+        Rename IdentifierCStringTranslator to IdentifierASCIIStringTranslator to make the text encoding
+        explicit.
+        (JSC::IdentifierASCIIStringTranslator::hash):
+        (JSC::IdentifierASCIIStringTranslator::equal):
+        (JSC::IdentifierASCIIStringTranslator::translate): Use the fast initialization from literal.
+        (JSC::Identifier::add):
+        * runtime/Identifier.h:
+        (JSC::Identifier::Identifier):
+
 2012-08-07  Simon Hausmann  <[email protected]>
 
         [Qt][Win] Remove pthreads linkage

Modified: trunk/Source/_javascript_Core/runtime/CommonIdentifiers.cpp (124921 => 124922)


--- trunk/Source/_javascript_Core/runtime/CommonIdentifiers.cpp	2012-08-07 21:42:05 UTC (rev 124921)
+++ trunk/Source/_javascript_Core/runtime/CommonIdentifiers.cpp	2012-08-07 21:46:07 UTC (rev 124922)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (C) 2003, 2007, 2009 Apple Inc. All rights reserved.
+ *  Copyright (C) 2003, 2007, 2009, 2012 Apple Inc. All rights reserved.
  *
  *  This library is free software; you can redistribute it and/or
  *  modify it under the terms of the GNU Library General Public
@@ -23,14 +23,12 @@
 
 namespace JSC {
 
-static const char* const nullCString = 0;
-
 #define INITIALIZE_PROPERTY_NAME(name) , name(globalData, #name)
 #define INITIALIZE_KEYWORD(name) , name##Keyword(globalData, #name)
 
 CommonIdentifiers::CommonIdentifiers(JSGlobalData* globalData)
-    : nullIdentifier(globalData, nullCString)
-    , emptyIdentifier(globalData, "")
+    : nullIdentifier()
+    , emptyIdentifier(Identifier::EmptyIdentifier)
     , underscoreProto(globalData, "__proto__")
     , thisIdentifier(globalData, "this")
     , useStrictIdentifier(globalData, "use strict")

Modified: trunk/Source/_javascript_Core/runtime/Identifier.cpp (124921 => 124922)


--- trunk/Source/_javascript_Core/runtime/Identifier.cpp	2012-08-07 21:42:05 UTC (rev 124921)
+++ trunk/Source/_javascript_Core/runtime/Identifier.cpp	2012-08-07 21:46:07 UTC (rev 124922)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
+ *  Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2012 Apple Inc. All rights reserved.
  *
  *  This library is free software; you can redistribute it and/or
  *  modify it under the terms of the GNU Library General Public
@@ -46,7 +46,7 @@
     delete table;
 }
 
-struct IdentifierCStringTranslator {
+struct IdentifierASCIIStringTranslator {
     static unsigned hash(const LChar* c)
     {
         return StringHasher::computeHashAndMaskTop8Bits<LChar>(c);
@@ -60,12 +60,8 @@
     static void translate(StringImpl*& location, const LChar* c, unsigned hash)
     {
         size_t length = strlen(reinterpret_cast<const char*>(c));
-        LChar* d;
-        StringImpl* r = StringImpl::createUninitialized(length, d).leakRef();
-        for (size_t i = 0; i != length; i++)
-            d[i] = c[i];
-        r->setHash(hash);
-        location = r;
+        location = StringImpl::createFromLiteral(c, length).leakRef();
+        location->setHash(hash);
     }
 };
 
@@ -96,10 +92,8 @@
 
 PassRefPtr<StringImpl> Identifier::add(JSGlobalData* globalData, const char* c)
 {
-    if (!c)
-        return 0;
-    if (!c[0])
-        return StringImpl::empty();
+    ASSERT(c);
+    ASSERT(c[0]);
     if (!c[1])
         return add(globalData, globalData->smallStrings.singleCharacterStringRep(c[0]));
 
@@ -110,7 +104,7 @@
     if (iter != literalIdentifierTable.end())
         return iter->second;
 
-    HashSet<StringImpl*>::AddResult addResult = identifierTable.add<const LChar*, IdentifierCStringTranslator>(reinterpret_cast<const LChar*>(c));
+    HashSet<StringImpl*>::AddResult addResult = identifierTable.add<const LChar*, IdentifierASCIIStringTranslator>(reinterpret_cast<const LChar*>(c));
 
     // If the string is newly-translated, then we need to adopt it.
     // The boolean in the pair tells us if that is so.

Modified: trunk/Source/_javascript_Core/runtime/Identifier.h (124921 => 124922)


--- trunk/Source/_javascript_Core/runtime/Identifier.h	2012-08-07 21:42:05 UTC (rev 124921)
+++ trunk/Source/_javascript_Core/runtime/Identifier.h	2012-08-07 21:46:07 UTC (rev 124922)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (C) 2003, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
+ *  Copyright (C) 2003, 2006, 2007, 2008, 2009, 2012 Apple Inc. All rights reserved.
  *
  *  This library is free software; you can redistribute it and/or
  *  modify it under the terms of the GNU Library General Public
@@ -35,12 +35,18 @@
         friend class Structure;
     public:
         Identifier() { }
+        enum EmptyIdentifierFlag { EmptyIdentifier };
+        Identifier(EmptyIdentifierFlag) : m_string(StringImpl::empty()) { }
 
-        Identifier(ExecState* exec, const char* s) : m_string(add(exec, s)) { } // Only to be used with string literals.
-        Identifier(ExecState* exec, StringImpl* rep) : m_string(add(exec, rep)) { } 
+        // Only to be used with string literals.
+        template<unsigned charactersCount>
+        Identifier(ExecState* exec, const char (&characters)[charactersCount]) : m_string(add(exec, characters)) { }
+        template<unsigned charactersCount>
+        Identifier(JSGlobalData* globalData, const char (&characters)[charactersCount]) : m_string(add(globalData, characters)) { }
+
+        Identifier(ExecState* exec, StringImpl* rep) : m_string(add(exec, rep)) { }
         Identifier(ExecState* exec, const UString& s) : m_string(add(exec, s.impl())) { }
 
-        Identifier(JSGlobalData* globalData, const char* s) : m_string(add(globalData, s)) { } // Only to be used with string literals.
         Identifier(JSGlobalData* globalData, const LChar* s, int length) : m_string(add(globalData, s, length)) { }
         Identifier(JSGlobalData* globalData, const UChar* s, int length) : m_string(add(globalData, s, length)) { }
         Identifier(JSGlobalData* globalData, StringImpl* rep) : m_string(add(globalData, rep)) { } 
@@ -80,8 +86,9 @@
         static bool equal(const StringImpl*, const UChar*, unsigned length);
         static bool equal(const StringImpl* a, const StringImpl* b) { return ::equal(a, b); }
 
-        JS_EXPORT_PRIVATE static PassRefPtr<StringImpl> add(ExecState*, const char*); // Only to be used with string literals.
-        static PassRefPtr<StringImpl> add(JSGlobalData*, const char*); // Only to be used with string literals.
+        // Only to be used with string literals.
+        static PassRefPtr<StringImpl> add(JSGlobalData*, const char*);
+        JS_EXPORT_PRIVATE static PassRefPtr<StringImpl> add(ExecState*, const char*);
 
     private:
         UString m_string;

Modified: trunk/Source/WTF/ChangeLog (124921 => 124922)


--- trunk/Source/WTF/ChangeLog	2012-08-07 21:42:05 UTC (rev 124921)
+++ trunk/Source/WTF/ChangeLog	2012-08-07 21:46:07 UTC (rev 124922)
@@ -1,3 +1,12 @@
+2012-08-07  Benjamin Poulain  <[email protected]>
+
+        Use the initialization from literal for JSC's Identifiers
+        https://bugs.webkit.org/show_bug.cgi?id=93193
+
+        Reviewed by Geoffrey Garen.
+
+        * wtf/text/StringImpl.h: Update the names for the HashTranslator used by Identifier.
+
 2012-07-19  Simon Hausmann  <[email protected]>
 
         [Qt] Remove Qt 4 specific code paths

Modified: trunk/Source/WTF/wtf/text/StringImpl.h (124921 => 124922)


--- trunk/Source/WTF/wtf/text/StringImpl.h	2012-08-07 21:42:05 UTC (rev 124921)
+++ trunk/Source/WTF/wtf/text/StringImpl.h	2012-08-07 21:46:07 UTC (rev 124922)
@@ -46,7 +46,7 @@
 // FIXME: This is a temporary layering violation while we move string code to WTF.
 // Landing the file moves in one patch, will follow on with patches to change the namespaces.
 namespace JSC {
-struct IdentifierCStringTranslator;
+struct IdentifierASCIIStringTranslator;
 namespace LLInt { class Data; }
 class LLIntOffsetsExtractor;
 template <typename T> struct IdentifierCharBufferTranslator;
@@ -69,7 +69,7 @@
 
 class StringImpl {
     WTF_MAKE_NONCOPYABLE(StringImpl); WTF_MAKE_FAST_ALLOCATED;
-    friend struct JSC::IdentifierCStringTranslator;
+    friend struct JSC::IdentifierASCIIStringTranslator;
     friend struct JSC::IdentifierCharBufferTranslator<LChar>;
     friend struct JSC::IdentifierCharBufferTranslator<UChar>;
     friend struct JSC::IdentifierLCharFromUCharTranslator;
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to