[webkit-changes] cvs commit: JavaScriptCore/kjs identifier.cpp identifier.h ustring.cpp ustring.h

Darin darin at opensource.apple.com
Fri Aug 19 13:24:18 PDT 2005


darin       05/08/19 13:24:18

  Modified:    .        ChangeLog
               kjs      identifier.cpp identifier.h ustring.cpp ustring.h
  Log:
          Reviewed by Maciej.
  
          - fixed http://bugzilla.opendarwin.org/show_bug.cgi?id=4435
            speed up JavaScript by tweaking the Identifier class
  
          * kjs/identifier.h: Add a new global nullIdentifier and make Identifier::null a function
          that returns it.
          * kjs/identifier.cpp: (KJS::Identifier::init): Initialize a global for the null identifier
          as well as all the other globals for special identifiers.
  
          * kjs/ustring.h: (KJS::UString::UString): Make this empty constructor inline.
          * kjs/ustring.cpp: Remove the old non-inline version.
  
  Revision  Changes    Path
  1.805     +15 -0     JavaScriptCore/ChangeLog
  
  Index: ChangeLog
  ===================================================================
  RCS file: /cvs/root/JavaScriptCore/ChangeLog,v
  retrieving revision 1.804
  retrieving revision 1.805
  diff -u -r1.804 -r1.805
  --- ChangeLog	19 Aug 2005 16:01:56 -0000	1.804
  +++ ChangeLog	19 Aug 2005 20:24:16 -0000	1.805
  @@ -1,3 +1,18 @@
  +2005-08-19  Darin Adler  <darin at apple.com>
  +
  +        Reviewed by Maciej.
  +
  +        - fixed http://bugzilla.opendarwin.org/show_bug.cgi?id=4435
  +          speed up JavaScript by tweaking the Identifier class
  +
  +        * kjs/identifier.h: Add a new global nullIdentifier and make Identifier::null a function
  +        that returns it.
  +        * kjs/identifier.cpp: (KJS::Identifier::init): Initialize a global for the null identifier
  +        as well as all the other globals for special identifiers.
  +
  +        * kjs/ustring.h: (KJS::UString::UString): Make this empty constructor inline.
  +        * kjs/ustring.cpp: Remove the old non-inline version.
  +
   2005-08-19  Mitz Pettel  <opendarwin.org at mitzpettel.com>
   
           Reviewed by Maciej.
  
  
  
  1.16      +15 -14    JavaScriptCore/kjs/identifier.cpp
  
  Index: identifier.cpp
  ===================================================================
  RCS file: /cvs/root/JavaScriptCore/kjs/identifier.cpp,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- identifier.cpp	14 Jul 2005 18:27:02 -0000	1.15
  +++ identifier.cpp	19 Aug 2005 20:24:17 -0000	1.16
  @@ -294,12 +294,6 @@
       free(oldTable);
   }
   
  -const Identifier &Identifier::null()
  -{
  -    static Identifier null;
  -    return null;
  -}
  -
   // Global constants for property name strings.
   
   #if !AVOID_STATIC_CONSTRUCTORS
  @@ -309,12 +303,16 @@
       // Define an Identifier-sized array of pointers to avoid static initialization.
       // Use an array of pointers instead of an array of char in case there is some alignment issue.
       #define DEFINE_GLOBAL(name, string) \
  -        void * name ## PropertyName[(sizeof(Identifier) + sizeof(void *) - 1) / sizeof(void *)];
  +        void * name[(sizeof(Identifier) + sizeof(void *) - 1) / sizeof(void *)];
   #endif
   
  -#define CALL_DEFINE_GLOBAL(name) DEFINE_GLOBAL(name, #name)
  -KJS_IDENTIFIER_EACH_GLOBAL(CALL_DEFINE_GLOBAL)
  -DEFINE_GLOBAL(specialPrototype, "__proto__")
  +const char * const nullCString = 0;
  +
  +DEFINE_GLOBAL(nullIdentifier, nullCString)
  +DEFINE_GLOBAL(specialPrototypePropertyName, "__proto__")
  +
  +#define DEFINE_PROPERTY_NAME_GLOBAL(name) DEFINE_GLOBAL(name ## PropertyName, #name)
  +KJS_IDENTIFIER_EACH_PROPERTY_NAME_GLOBAL(DEFINE_PROPERTY_NAME_GLOBAL)
   
   void Identifier::init()
   {
  @@ -322,10 +320,13 @@
       static bool initialized;
       if (!initialized) {
           // Use placement new to initialize the globals.
  -        #define PLACEMENT_NEW_GLOBAL(name, string) new (&name ## PropertyName) Identifier(string);
  -        #define CALL_PLACEMENT_NEW_GLOBAL(name) PLACEMENT_NEW_GLOBAL(name, #name)
  -        KJS_IDENTIFIER_EACH_GLOBAL(CALL_PLACEMENT_NEW_GLOBAL)
  -        PLACEMENT_NEW_GLOBAL(specialPrototype, "__proto__")
  +
  +        new (&nullIdentifier) Identifier(nullCString);
  +        new (&specialPrototypePropertyName) Identifier("__proto__");
  +
  +        #define PLACEMENT_NEW_PROPERTY_NAME_GLOBAL(name) new(&name ## PropertyName) Identifier(#name);
  +        KJS_IDENTIFIER_EACH_PROPERTY_NAME_GLOBAL(PLACEMENT_NEW_PROPERTY_NAME_GLOBAL)
  +
           initialized = true;
       }
   #endif
  
  
  
  1.16      +13 -5     JavaScriptCore/kjs/identifier.h
  
  Index: identifier.h
  ===================================================================
  RCS file: /cvs/root/JavaScriptCore/kjs/identifier.h,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- identifier.h	14 Jul 2005 18:27:02 -0000	1.15
  +++ identifier.h	19 Aug 2005 20:24:17 -0000	1.16
  @@ -93,6 +93,13 @@
           static int _keyCount;
       };
       
  +#if !KJS_IDENTIFIER_HIDE_GLOBALS
  +    extern const Identifier nullIdentifier;
  +
  +    inline const Identifier &Identifier::null()
  +        { return nullIdentifier; }
  +#endif
  +
       inline bool operator==(const Identifier &a, const Identifier &b)
           { return Identifier::equal(a, b); }
   
  @@ -104,7 +111,7 @@
   
       // List of property names, passed to a macro so we can do set them up various
       // ways without repeating the list.
  -    #define KJS_IDENTIFIER_EACH_GLOBAL(macro) \
  +    #define KJS_IDENTIFIER_EACH_PROPERTY_NAME_GLOBAL(macro) \
           macro(arguments) \
           macro(callee) \
           macro(constructor) \
  @@ -121,10 +128,11 @@
   
       // Define external global variables for all property names above (and one more).
   #if !KJS_IDENTIFIER_HIDE_GLOBALS
  -    #define KJS_IDENTIFIER_DECLARE_GLOBAL(name) extern const Identifier name ## PropertyName;
  -    KJS_IDENTIFIER_EACH_GLOBAL(KJS_IDENTIFIER_DECLARE_GLOBAL)
  -    KJS_IDENTIFIER_DECLARE_GLOBAL(specialPrototype)
  -    #undef KJS_IDENTIFIER_DECLARE_GLOBAL
  +    extern const Identifier specialPrototypePropertyName;
  +
  +    #define KJS_IDENTIFIER_DECLARE_PROPERTY_NAME_GLOBAL(name) extern const Identifier name ## PropertyName;
  +    KJS_IDENTIFIER_EACH_PROPERTY_NAME_GLOBAL(KJS_IDENTIFIER_DECLARE_PROPERTY_NAME_GLOBAL)
  +    #undef KJS_IDENTIFIER_DECLARE_PROPERTY_NAME_GLOBAL
   #endif
   
   }
  
  
  
  1.59      +1 -6      JavaScriptCore/kjs/ustring.cpp
  
  Index: ustring.cpp
  ===================================================================
  RCS file: /cvs/root/JavaScriptCore/kjs/ustring.cpp,v
  retrieving revision 1.58
  retrieving revision 1.59
  diff -u -r1.58 -r1.59
  --- ustring.cpp	1 Aug 2005 05:02:13 -0000	1.58
  +++ ustring.cpp	19 Aug 2005 20:24:17 -0000	1.59
  @@ -389,11 +389,6 @@
   }
   
   
  -UString::UString()
  -{
  -  attach(&Rep::null);
  -}
  -
   UString::UString(char c)
   {
       UChar *d = static_cast<UChar *>(kjs_fast_malloc(sizeof(UChar)));
  @@ -1126,7 +1121,7 @@
     if (pos == 0 && len == s)
       return *this;
   
  -  UString::Rep *newRep = Rep::create(rep, pos, len);
  +  Rep *newRep = Rep::create(rep, pos, len);
     UString result(newRep);
     newRep->deref();
   
  
  
  
  1.38      +5 -3      JavaScriptCore/kjs/ustring.h
  
  Index: ustring.h
  ===================================================================
  RCS file: /cvs/root/JavaScriptCore/kjs/ustring.h,v
  retrieving revision 1.37
  retrieving revision 1.38
  diff -u -r1.37 -r1.38
  --- ustring.h	14 Jul 2005 18:27:03 -0000	1.37
  +++ ustring.h	19 Aug 2005 20:24:17 -0000	1.38
  @@ -204,9 +204,6 @@
        * @internal
        */
       struct Rep {
  -      friend class UString;
  -      friend bool operator==(const UString&, const UString&);
  -      
         static Rep *create(UChar *d, int l);
         static Rep *createCopying(const UChar *d, int l);
         static Rep *create(Rep *base, int offset, int length);
  @@ -517,6 +514,11 @@
     // Returns -1 if the sequence is not valid (including presence of extra bytes).
     int decodeUTF8Sequence(const char *);
   
  +inline UString::UString()
  +{
  +    attach(&Rep::null);
  +}
  +
   } // namespace
   
   #endif
  
  
  



More information about the webkit-changes mailing list