Bug 41055

Summary: Simplify hash lookups at RegExp caching
Product: WebKit Reporter: Renata Hodovan <rhodovan.u-szeged>
Component: JavaScriptCoreAssignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal CC: abarth, commit-queue, eric, ggaren, oliver, ossy, webkit.review.bot, zherczeg
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: PC   
OS: Linux   
Bug Depends on: 41205, 41240    
Bug Blocks:    
Attachments:
Description Flags
Simplify hash lookups in RegExp caching
none
Simplify hash lookups in RegExp caching
none
Patch
none
Patch oliver: review+

Description Renata Hodovan 2010-06-23 02:46:12 PDT
1) With giving to RegExpCache::create an extra iterator parameter we can simplify some hash lookups.
2) We can collapse the two version of RegExp::create into one, in which we check whether flags are given or not.
Comment 1 Renata Hodovan 2010-06-23 02:52:02 PDT
Created attachment 59496 [details]
Simplify hash lookups in RegExp caching
Comment 2 Gabor Loki 2010-06-24 01:55:35 PDT
Comment on attachment 59496 [details]
Simplify hash lookups in RegExp caching

> +PassRefPtr<RegExp> RegExpCache::create(const UString& patternString, const UString& flags, HashMap<RegExpKey, RefPtr<RegExp> >::iterator iterator) 

The RegExpCacheMap::iterator will look better.

> -PassRefPtr<RegExp> RegExp::create(JSGlobalData* globalData, const UString& pattern)
> -{
> -    return adoptRef(new RegExp(globalData, pattern));
> -}
> -
>  PassRefPtr<RegExp> RegExp::create(JSGlobalData* globalData, const UString& pattern, const UString& flags)
>  {
> +    if (flags.isNull())
> +        return adoptRef(new RegExp(globalData, pattern));
>      return adoptRef(new RegExp(globalData, pattern, flags));
>  }

If you propose this merge, what is the reason not to merge the RegExp constructors and create functions?
Comment 3 Renata Hodovan 2010-06-24 08:44:32 PDT
> The RegExpCacheMap::iterator will look better.
You're right. This way is really better.

> > -PassRefPtr<RegExp> RegExp::create(JSGlobalData* globalData, const UString& pattern)
> > -{
> > -    return adoptRef(new RegExp(globalData, pattern));
> > -}
> > -
> >  PassRefPtr<RegExp> RegExp::create(JSGlobalData* globalData, const UString& pattern, const UString& flags)
> >  {
> > +    if (flags.isNull())
> > +        return adoptRef(new RegExp(globalData, pattern));
> >      return adoptRef(new RegExp(globalData, pattern, flags));
> >  }
> 
> If you propose this merge, what is the reason not to merge the RegExp constructors and create functions?

I agree that we should merge RegExp constructors. But I think it's more prefered to call the public RegExp constructor from the public create function. I have seen examples for this, but maybe I'm wrong. Any comments?
Comment 4 Renata Hodovan 2010-06-24 08:45:12 PDT
Created attachment 59657 [details]
Simplify hash lookups in RegExp caching
Comment 5 Renata Hodovan 2010-06-24 11:59:00 PDT
> ... to call the public RegExp constructor from the public create function. 
... to call the *private* RegExp constructor from the public create function.
Comment 6 Geoffrey Garen 2010-06-24 14:12:27 PDT
Comment on attachment 59657 [details]
Simplify hash lookups in RegExp caching

r=me

Nice cleanup.
Comment 7 WebKit Review Bot 2010-06-25 00:22:43 PDT
http://trac.webkit.org/changeset/61833 might have broken GTK Linux 64-bit Debug
Comment 8 Csaba Osztrogonác 2010-06-25 03:21:31 PDT
Reopen because it was rolled out by http://trac.webkit.org/changeset/61845
Comment 9 WebKit Commit Bot 2010-06-25 17:42:03 PDT
Comment on attachment 59657 [details]
Simplify hash lookups in RegExp caching

Clearing flags on attachment: 59657

Committed r61924: <http://trac.webkit.org/changeset/61924>
Comment 10 WebKit Commit Bot 2010-06-25 17:42:08 PDT
All reviewed patches have been landed.  Closing bug.
Comment 11 Csaba Osztrogonác 2010-06-25 17:49:25 PDT
Rolled out and reopened again. Sorry, I missed 
to remove cq+ after the previous roll-out. :(

Zoltan, if you would like to land cq+ -ed patch manually, 
next time please set cq- before it, and add comment to
the bug with the revision number.
Comment 12 Adam Barth 2010-06-25 18:03:19 PDT
Or you can use "webkit-patch land" which will take care of all that for you.
Comment 13 Geoffrey Garen 2010-06-28 11:59:35 PDT
The reason this patch was crashing:

In the case where the cache is full, it reuses the insertion iterator after evicting an item. You can't modify the table while maintaining an iterator into the table.
Comment 14 Geoffrey Garen 2010-06-28 12:15:44 PDT
Created attachment 59920 [details]
Patch
Comment 15 Geoffrey Garen 2010-06-28 12:18:13 PDT
Created attachment 59921 [details]
Patch
Comment 16 Oliver Hunt 2010-07-02 12:40:53 PDT
Comment on attachment 59921 [details]
Patch

r=me
Comment 17 Geoffrey Garen 2010-07-02 14:34:55 PDT
Committed revision 62405.