Bug 75323 - Use HashMap<OwnPtr> for UserScriptMap and UserStyleSheetMap
Summary: Use HashMap<OwnPtr> for UserScriptMap and UserStyleSheetMap
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Page Loading (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Caio Marcelo de Oliveira Filho
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-12-28 12:46 PST by Caio Marcelo de Oliveira Filho
Modified: 2011-12-29 02:50 PST (History)
2 users (show)

See Also:


Attachments
Patch (7.30 KB, patch)
2011-12-28 12:51 PST, Caio Marcelo de Oliveira Filho
no flags Details | Formatted Diff | Diff
Patch (7.29 KB, patch)
2011-12-28 13:11 PST, Caio Marcelo de Oliveira Filho
darin: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Caio Marcelo de Oliveira Filho 2011-12-28 12:46:46 PST
Use HashMap<OwnPtr> for UserScriptMap and UserStyleSheetMap
Comment 1 Caio Marcelo de Oliveira Filho 2011-12-28 12:51:26 PST
Created attachment 120692 [details]
Patch
Comment 2 Darin Adler 2011-12-28 12:56:59 PST
Comment on attachment 120692 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=120692&action=review

Great to do this! A couple things to fix.

> Source/WebCore/page/PageGroup.cpp:288
> -    UserScriptVector*& scriptsInWorld = m_userScripts->add(world, 0).first->second;
> -    if (!scriptsInWorld)
> +    UserScriptVector* scriptsInWorld = m_userScripts->get(world);
> +    if (!scriptsInWorld) {
>          scriptsInWorld = new UserScriptVector;
> +        m_userScripts->add(world, adoptPtr(scriptsInWorld));
> +    }

This adds unnecessary complexity and additional hash table lookups. You can make a smaller change like this:

    OwnPtr<UserScriptVector>& scriptsInWorld = m_userScripts->add(world, nullptr).first->second;
    if (!scriptsInWorld)
        scriptsInWorld = adoptPtr(new UserScriptVector);

> Source/WebCore/page/PageGroup.cpp:307
> -    UserStyleSheetVector*& styleSheetsInWorld = m_userStyleSheets->add(world, 0).first->second;
> -    if (!styleSheetsInWorld)
> +    UserStyleSheetVector* styleSheetsInWorld = m_userStyleSheets->get(world);
> +    if (!styleSheetsInWorld) {
>          styleSheetsInWorld = new UserStyleSheetVector;
> +        m_userStyleSheets->add(world, adoptPtr(styleSheetsInWorld));
> +    }

Same thing here. Just change the type to OwnPtr.

> Source/WebCore/page/PageGroup.cpp:397
> +    if (m_userScripts)
>          m_userScripts.clear();

No need for the if here. It’s fine to just unconditionally call clear.
Comment 3 Caio Marcelo de Oliveira Filho 2011-12-28 13:11:33 PST
Created attachment 120695 [details]
Patch
Comment 4 Caio Marcelo de Oliveira Filho 2011-12-29 02:50:54 PST
Committed r103793: <http://trac.webkit.org/changeset/103793>