Ignore:
Timestamp:
Mar 5, 2010, 3:29:13 PM (15 years ago)
Author:
[email protected]
Message:

2010-03-05 Oliver Hunt <[email protected]>

Reviewed by Gavin Barraclough.

JSC should cache int to Identifier conversion as it does for ordinary strings
https://bugs.webkit.org/show_bug.cgi?id=35814

Make the NumericStrings cache cache unsigned ints in addition to signed.
We keep them separate from the int cache as it both simplifies code, and
also because the unsigned path is exclusive to property access and therefore
seems to have different usage patterns.

The primary trigger for the unsigned to Identifier propertyName conversion
is the construction of array-like objects out of normal objects. Given these
tend to be relative small numbers, and the array-like behaviour lends itself
to sequential values this patch also adds a non-colliding cache for all small
numbers.

  • JavaScriptCore.exp:
  • runtime/Identifier.cpp: (JSC::Identifier::from):
  • runtime/Identifier.h:
  • runtime/NumericStrings.h: (JSC::NumericStrings::add): (JSC::NumericStrings::lookup): (JSC::NumericStrings::lookupSmallString):
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/runtime/NumericStrings.h

    r47622 r55599  
    4646        UString add(int i)
    4747        {
     48            if (static_cast<unsigned>(i) < cacheSize)
     49                return lookupSmallString(static_cast<unsigned>(i));
    4850            CacheEntry<int>& entry = lookup(i);
    4951            if (i == entry.key && !entry.value.isNull())
     
    5456        }
    5557
     58        UString add(unsigned i)
     59        {
     60            if (i < cacheSize)
     61                return lookupSmallString(static_cast<unsigned>(i));
     62            CacheEntry<unsigned>& entry = lookup(i);
     63            if (i == entry.key && !entry.value.isNull())
     64                return entry.value;
     65            entry.key = i;
     66            entry.value = UString::from(i);
     67            return entry.value;
     68        }
    5669    private:
    5770        static const size_t cacheSize = 64;
     
    6578        CacheEntry<double>& lookup(double d) { return doubleCache[WTF::FloatHash<double>::hash(d) & (cacheSize - 1)]; }
    6679        CacheEntry<int>& lookup(int i) { return intCache[WTF::IntHash<int>::hash(i) & (cacheSize - 1)]; }
     80        CacheEntry<unsigned>& lookup(unsigned i) { return unsignedCache[WTF::IntHash<unsigned>::hash(i) & (cacheSize - 1)]; }
     81        const UString& lookupSmallString(unsigned i)
     82        {
     83            ASSERT(i < cacheSize);
     84            if (smallIntCache[i].isNull())
     85                smallIntCache[i] = UString::from(i);
     86            return smallIntCache[i];
     87        }
    6788
    6889        CacheEntry<double> doubleCache[cacheSize];
    6990        CacheEntry<int> intCache[cacheSize];
     91        CacheEntry<unsigned> unsignedCache[cacheSize];
     92        UString smallIntCache[cacheSize];
    7093    };
    7194
Note: See TracChangeset for help on using the changeset viewer.