Bug 124374 - Web Inspector: Simply generated domain dispatch methods for domains with few commands
Summary: Web Inspector: Simply generated domain dispatch methods for domains with few ...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Inspector (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Joseph Pecoraro
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2013-11-14 12:07 PST by Joseph Pecoraro
Modified: 2013-11-14 13:28 PST (History)
5 users (show)

See Also:


Attachments
[PATCH] Proposed Fix (6.41 KB, patch)
2013-11-14 12:20 PST, Joseph Pecoraro
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Joseph Pecoraro 2013-11-14 12:07:59 PST
A bunch of domains have only a few methods. The hash lookup does not make sense.

Turn:

    void InspectorInspectorBackendDispatcher::dispatch(long callId, const String& method, PassRefPtr<InspectorObject> message)
    {
        Ref<InspectorInspectorBackendDispatcher> protect(*this);

        typedef void (InspectorInspectorBackendDispatcher::*CallHandler)(long callId, const InspectorObject& message);
        typedef HashMap<String, CallHandler> DispatchMap;
        DEFINE_STATIC_LOCAL(DispatchMap, dispatchMap, ());
        if (dispatchMap.isEmpty()) {
            static const struct MethodTable {
                const char* name;
                CallHandler handler;
            } commands[] = {
                { "enable",  &InspectorInspectorBackendDispatcher::enable },
                { "disable",  &InspectorInspectorBackendDispatcher::disable },
            };
            size_t length = WTF_ARRAY_LENGTH(commands);
            for (size_t i = 0; i < length; ++i)
                dispatchMap.add(commands[i].name, commands[i].handler);
        }

        HashMap<String, CallHandler>::iterator it = dispatchMap.find(method);
        if (it == dispatchMap.end()) {
            m_backendDispatcher->reportProtocolError(&callId, InspectorBackendDispatcher::MethodNotFound, String("'") + "Inspector" + '.' + method + "' was not found");
            return;
        }

        ((*this).*it->value)(callId, *message.get());
    }

into:

    void InspectorInspectorBackendDispatcher::dispatch(long callId, const String& method, PassRefPtr<InspectorObject> message)
    {
        Ref<InspectorInspectorBackendDispatcher> protect(*this);

        if (method == "enable")
            enable(callId, *message.get());
        else if (method == "disable")
            disable(callId, *message.get());
        else
            m_backendDispatcher->reportProtocolError(&callId, InspectorBackendDispatcher::MethodNotFound, String("'") + "Inspector" + '.' + method + "' was not found");
    }
Comment 1 Radar WebKit Bug Importer 2013-11-14 12:08:30 PST
<rdar://problem/15472278>
Comment 2 Joseph Pecoraro 2013-11-14 12:20:03 PST
Created attachment 216967 [details]
[PATCH] Proposed Fix
Comment 3 WebKit Commit Bot 2013-11-14 13:28:37 PST
Comment on attachment 216967 [details]
[PATCH] Proposed Fix

Clearing flags on attachment: 216967

Committed r159308: <http://trac.webkit.org/changeset/159308>
Comment 4 WebKit Commit Bot 2013-11-14 13:28:38 PST
All reviewed patches have been landed.  Closing bug.