Changeset 61924 in webkit


Ignore:
Timestamp:
Jun 25, 2010 5:41:49 PM (14 years ago)
Author:
commit-queue@webkit.org
Message:

2010-06-25 Renata Hodovan <reni@inf.u-szeged.hu>

Reviewed by Geoffrey Garen.

Merge RegExp constructor and RegExp::create methods into one.
Both of function are called with tree parameters and check whether
flags (the third param) is given or not.
Simplify hash lookups in RegExpCache::create with giving them an extra
iterator parameter.
https://bugs.webkit.org/show_bug.cgi?id=41055

  • runtime/RegExp.cpp: (JSC::RegExp::RegExp):
  • runtime/RegExp.h:
  • runtime/RegExpCache.cpp: (JSC::RegExpCache::lookupOrCreate): (JSC::RegExpCache::create):
  • runtime/RegExpCache.h:
Location:
trunk/JavaScriptCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r61882 r61924  
     12010-06-25  Renata Hodovan  <reni@inf.u-szeged.hu>
     2
     3        Reviewed by Geoffrey Garen.
     4
     5        Merge RegExp constructor and RegExp::create methods into one.
     6        Both of function are called with tree parameters and check whether
     7        flags (the third param) is given or not.
     8        Simplify hash lookups in RegExpCache::create with giving them an extra
     9        iterator parameter.
     10        https://bugs.webkit.org/show_bug.cgi?id=41055
     11
     12        * runtime/RegExp.cpp:
     13        (JSC::RegExp::RegExp):
     14        * runtime/RegExp.h:
     15        * runtime/RegExpCache.cpp:
     16        (JSC::RegExpCache::lookupOrCreate):
     17        (JSC::RegExpCache::create):
     18        * runtime/RegExpCache.h:
     19
    1202010-06-25  Jedrzej Nowacki  <jedrzej.nowacki@nokia.com>
    221
  • trunk/JavaScriptCore/runtime/RegExp.cpp

    r61845 r61924  
    4747namespace JSC {
    4848
    49 inline RegExp::RegExp(JSGlobalData* globalData, const UString& pattern)
    50     : m_pattern(pattern)
    51     , m_flagBits(0)
    52     , m_constructionError(0)
    53     , m_numSubpatterns(0)
    54 {
    55     compile(globalData);
    56 }
    57 
    5849inline RegExp::RegExp(JSGlobalData* globalData, const UString& pattern, const UString& flags)
    5950    : m_pattern(pattern)
     
    6455    // NOTE: The global flag is handled on a case-by-case basis by functions like
    6556    // String::match and RegExpObject::match.
    66     if (flags.find('g') != UString::NotFound)
    67         m_flagBits |= Global;
    68     if (flags.find('i') != UString::NotFound)
    69         m_flagBits |= IgnoreCase;
    70     if (flags.find('m') != UString::NotFound)
    71         m_flagBits |= Multiline;
    72 
     57    if (!flags.isNull()) {
     58        if (flags.find('g') != UString::NotFound)
     59            m_flagBits |= Global;
     60        if (flags.find('i') != UString::NotFound)
     61            m_flagBits |= IgnoreCase;
     62        if (flags.find('m') != UString::NotFound)
     63            m_flagBits |= Multiline;
     64    }
    7365    compile(globalData);
    7466}
     
    8072}
    8173#endif
    82 
    83 PassRefPtr<RegExp> RegExp::create(JSGlobalData* globalData, const UString& pattern)
    84 {
    85     return adoptRef(new RegExp(globalData, pattern));
    86 }
    8774
    8875PassRefPtr<RegExp> RegExp::create(JSGlobalData* globalData, const UString& pattern, const UString& flags)
  • trunk/JavaScriptCore/runtime/RegExp.h

    r61845 r61924  
    3838    class RegExp : public RefCounted<RegExp> {
    3939    public:
    40         static PassRefPtr<RegExp> create(JSGlobalData* globalData, const UString& pattern);
    4140        static PassRefPtr<RegExp> create(JSGlobalData* globalData, const UString& pattern, const UString& flags);
    4241#if !ENABLE(YARR)
     
    5756
    5857    private:
    59         RegExp(JSGlobalData* globalData, const UString& pattern);
    6058        RegExp(JSGlobalData* globalData, const UString& pattern, const UString& flags);
    6159
  • trunk/JavaScriptCore/runtime/RegExpCache.cpp

    r61845 r61924  
    3838        if (!result.second)
    3939            return result.first->second;
     40        else
     41            return create(patternString, flags, result.first);
    4042    }
    41     return create(patternString, flags);
     43    return create(patternString, flags, m_cacheMap.end());
    4244}
    4345
    44 PassRefPtr<RegExp> RegExpCache::create(const UString& patternString, const UString& flags)
     46PassRefPtr<RegExp> RegExpCache::create(const UString& patternString, const UString& flags, RegExpCacheMap::iterator iterator)
    4547{
    46     RefPtr<RegExp> regExp;
    47 
    48     if (!flags.isNull())
    49         regExp = RegExp::create(m_globalData, patternString, flags);
    50     else
    51         regExp = RegExp::create(m_globalData, patternString);
     48    RefPtr<RegExp> regExp = RegExp::create(m_globalData, patternString, flags);
    5249
    5350    if (patternString.size() >= maxCacheablePatternLength)
     
    6360
    6461    RegExpKey key = RegExpKey(flags, patternString);
    65     m_cacheMap.set(key, regExp);
     62    iterator->first = key;
     63    iterator->second = regExp;
    6664    patternKeyArray[m_nextKeyToEvict].flagsValue = key.flagsValue;
    6765    patternKeyArray[m_nextKeyToEvict].pattern = patternString.rep();
  • trunk/JavaScriptCore/runtime/RegExpCache.h

    r61845 r61924  
    3636
    3737class RegExpCache {
     38
     39typedef HashMap<RegExpKey, RefPtr<RegExp> > RegExpCacheMap;
     40
    3841public:
    3942    PassRefPtr<RegExp> lookupOrCreate(const UString& patternString, const UString& flags);
    40     PassRefPtr<RegExp> create(const UString& patternString, const UString& flags);
     43    PassRefPtr<RegExp> create(const UString& patternString, const UString& flags, RegExpCacheMap::iterator iterator);
    4144    RegExpCache(JSGlobalData* globalData);
    4245
     
    4548    static const int maxCacheableEntries = 256;
    4649
    47     typedef HashMap<RegExpKey, RefPtr<RegExp> > RegExpCacheMap;
    4850    RegExpKey patternKeyArray[maxCacheableEntries];
    4951    RegExpCacheMap m_cacheMap;
Note: See TracChangeset for help on using the changeset viewer.