Ignore:
Timestamp:
Jun 8, 2011, 2:54:15 PM (14 years ago)
Author:
[email protected]
Message:

2011-06-08 Oliver Hunt <[email protected]>

Reviewed by Geoffrey Garen.

Add faster lookup cache for multi character identifiers
https://bugs.webkit.org/show_bug.cgi?id=62327

Add a non-hash lookup for mutiple character identifiers. This saves us from
adding repeated identifiers to the ParserArena's identifier list as people
tend to not start all their variables and properties with the same character
and happily identifier locality works in our favour.

  • parser/ParserArena.h: (JSC::IdentifierArena::isEmpty): (JSC::IdentifierArena::clear): (JSC::IdentifierArena::makeIdentifier):
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/parser/ParserArena.h

    r87838 r88394  
    4646        const Identifier& makeNumericIdentifier(JSGlobalData*, double number);
    4747
     48        bool isEmpty() const { return m_identifiers.isEmpty(); }
     49
     50    public:
     51        static const int MaximumCachableCharacter = 128;
     52        typedef SegmentedVector<Identifier, 64> IdentifierVector;
    4853        void clear()
    4954        {
    5055            m_identifiers.clear();
    51             for (unsigned  i = 0; i < 128; i++)
     56            for (int i = 0; i < MaximumCachableCharacter; i++)
    5257                m_shortIdentifiers[i] = 0;
     58            for (int i = 0; i < MaximumCachableCharacter; i++)
     59                m_recentIdentifiers[i] = 0;
    5360        }
    54         bool isEmpty() const { return m_identifiers.isEmpty(); }
    5561
    5662    private:
    57         static const int MaximumCachableCharacter = 128;
    58         typedef SegmentedVector<Identifier, 64> IdentifierVector;
    5963        IdentifierVector m_identifiers;
    6064        FixedArray<Identifier*, MaximumCachableCharacter> m_shortIdentifiers;
     65        FixedArray<Identifier*, MaximumCachableCharacter> m_recentIdentifiers;
    6166    };
    6267
    6368    ALWAYS_INLINE const Identifier& IdentifierArena::makeIdentifier(JSGlobalData* globalData, const UChar* characters, size_t length)
    6469    {
    65         if (length == 1 && characters[0] < MaximumCachableCharacter) {
     70        if (characters[0] >= MaximumCachableCharacter) {
     71            m_identifiers.append(Identifier(globalData, characters, length));
     72            return m_identifiers.last();
     73        }
     74        if (length == 1) {
    6675            if (Identifier* ident = m_shortIdentifiers[characters[0]])
    6776                return *ident;
     
    7079            return m_identifiers.last();
    7180        }
     81        Identifier* ident = m_recentIdentifiers[characters[0]];
     82        if (ident && Identifier::equal(ident->impl(), characters, length))
     83            return *ident;
    7284        m_identifiers.append(Identifier(globalData, characters, length));
     85        m_recentIdentifiers[characters[0]] = &m_identifiers.last();
    7386        return m_identifiers.last();
    7487    }
Note: See TracChangeset for help on using the changeset viewer.