Title: [190540] trunk/Source/WebInspectorUI
Revision
190540
Author
[email protected]
Date
2015-10-02 19:28:22 -0700 (Fri, 02 Oct 2015)

Log Message

Web Inspector: Cleanup DebuggerManager, reduce `delete` and use Maps instead of objects
https://bugs.webkit.org/show_bug.cgi?id=149760

Reviewed by Joseph Pecoraro.

Replaced objects used as hashmaps with Map.

* UserInterface/Controllers/DebuggerManager.js:
(WebInspector.DebuggerManager.prototype.breakpointsForSourceCode):
(WebInspector.DebuggerManager.prototype.breakpointForIdentifier):
(WebInspector.DebuggerManager.prototype.scriptForIdentifier):
(WebInspector.DebuggerManager.prototype.scriptsForURL):
(WebInspector.DebuggerManager.prototype.get knownNonResourceScripts):
(WebInspector.DebuggerManager.prototype.removeBreakpoint):
(WebInspector.DebuggerManager.prototype.breakpointResolved):
(WebInspector.DebuggerManager.prototype.reset):
(WebInspector.DebuggerManager.prototype.scriptDidParse):
(WebInspector.DebuggerManager.prototype._sourceCodeLocationFromPayload):
(WebInspector.DebuggerManager.prototype._setBreakpoint.didSetBreakpoint):
(WebInspector.DebuggerManager.prototype._setBreakpoint):
(WebInspector.DebuggerManager.prototype._removeBreakpoint.didRemoveBreakpoint):
(WebInspector.DebuggerManager.prototype._removeBreakpoint):

Modified Paths

Diff

Modified: trunk/Source/WebInspectorUI/ChangeLog (190539 => 190540)


--- trunk/Source/WebInspectorUI/ChangeLog	2015-10-03 01:13:11 UTC (rev 190539)
+++ trunk/Source/WebInspectorUI/ChangeLog	2015-10-03 02:28:22 UTC (rev 190540)
@@ -1,3 +1,28 @@
+2015-10-02  Matt Baker  <[email protected]>
+
+        Web Inspector: Cleanup DebuggerManager, reduce `delete` and use Maps instead of objects
+        https://bugs.webkit.org/show_bug.cgi?id=149760
+
+        Reviewed by Joseph Pecoraro.
+
+        Replaced objects used as hashmaps with Map.
+
+        * UserInterface/Controllers/DebuggerManager.js:
+        (WebInspector.DebuggerManager.prototype.breakpointsForSourceCode):
+        (WebInspector.DebuggerManager.prototype.breakpointForIdentifier):
+        (WebInspector.DebuggerManager.prototype.scriptForIdentifier):
+        (WebInspector.DebuggerManager.prototype.scriptsForURL):
+        (WebInspector.DebuggerManager.prototype.get knownNonResourceScripts):
+        (WebInspector.DebuggerManager.prototype.removeBreakpoint):
+        (WebInspector.DebuggerManager.prototype.breakpointResolved):
+        (WebInspector.DebuggerManager.prototype.reset):
+        (WebInspector.DebuggerManager.prototype.scriptDidParse):
+        (WebInspector.DebuggerManager.prototype._sourceCodeLocationFromPayload):
+        (WebInspector.DebuggerManager.prototype._setBreakpoint.didSetBreakpoint):
+        (WebInspector.DebuggerManager.prototype._setBreakpoint):
+        (WebInspector.DebuggerManager.prototype._removeBreakpoint.didRemoveBreakpoint):
+        (WebInspector.DebuggerManager.prototype._removeBreakpoint):
+
 2015-10-02  Devin Rousso  <[email protected]>
 
         Web Inspector: Copying inline style text puts "undefined" in the pasteboard

Modified: trunk/Source/WebInspectorUI/UserInterface/Controllers/DebuggerManager.js (190539 => 190540)


--- trunk/Source/WebInspectorUI/UserInterface/Controllers/DebuggerManager.js	2015-10-03 01:13:11 UTC (rev 190539)
+++ trunk/Source/WebInspectorUI/UserInterface/Controllers/DebuggerManager.js	2015-10-03 02:28:22 UTC (rev 190540)
@@ -53,9 +53,9 @@
         this._allUncaughtExceptionsBreakpoint = new WebInspector.Breakpoint(specialBreakpointLocation, !this._allUncaughtExceptionsBreakpointEnabledSetting.value);
 
         this._breakpoints = [];
-        this._breakpointURLMap = {};
-        this._breakpointScriptIdentifierMap = {};
-        this._breakpointIdMap = {};
+        this._breakpointURLMap = new Map;
+        this._breakpointScriptIdentifierMap = new Map;
+        this._breakpointIdMap = new Map;
 
         this._nextBreakpointActionIdentifier = 1;
 
@@ -63,8 +63,8 @@
         this._pauseReason = null;
         this._pauseData = null;
 
-        this._scriptIdMap = {};
-        this._scriptURLMap = {};
+        this._scriptIdMap = new Map;
+        this._scriptURLMap = new Map;
 
         this._breakpointsSetting = new WebInspector.Setting("breakpoints", []);
         this._breakpointsEnabledSetting = new WebInspector.Setting("breakpoints-enabled", true);
@@ -276,16 +276,18 @@
             });
         }
 
-        if (sourceCode.url in this._breakpointURLMap) {
-            var urlBreakpoint = this._breakpointURLMap[sourceCode.url] || [];
-            this._associateBreakpointsWithSourceCode(urlBreakpoint, sourceCode);
-            return urlBreakpoint;
+        let urlBreakpoints = this._breakpointURLMap.get(sourceCode.url);
+        if (urlBreakpoints) {
+            this._associateBreakpointsWithSourceCode(urlBreakpoints, sourceCode);
+            return urlBreakpoints;
         }
 
-        if (sourceCode instanceof WebInspector.Script && sourceCode.id in this._breakpointScriptIdentifierMap) {
-            var scriptIdentifierBreakpoints = this._breakpointScriptIdentifierMap[sourceCode.id] || [];
-            this._associateBreakpointsWithSourceCode(scriptIdentifierBreakpoints, sourceCode);
-            return scriptIdentifierBreakpoints;
+        if (sourceCode instanceof WebInspector.Script) {
+            let scriptIdentifierBreakpoints = this._breakpointScriptIdentifierMap.get(sourceCode.id);
+            if (scriptIdentifierBreakpoints) {
+                this._associateBreakpointsWithSourceCode(scriptIdentifierBreakpoints, sourceCode);
+                return scriptIdentifierBreakpoints;
+            }
         }
 
         return [];
@@ -293,18 +295,18 @@
 
     breakpointForIdentifier(id)
     {
-        return this._breakpointIdMap[id];
+        return this._breakpointIdMap.get(id) || null;
     }
 
     scriptForIdentifier(id)
     {
-        return this._scriptIdMap[id] || null;
+        return this._scriptIdMap.get(id) || null;
     }
 
     scriptsForURL(url)
     {
         // FIXME: This may not be safe. A Resource's URL may differ from a Script's URL.
-        return this._scriptURLMap[url] || [];
+        return this._scriptURLMap.get(url) || [];
     }
 
     continueToLocation(scriptIdentifier, lineNumber, columnNumber)
@@ -314,9 +316,8 @@
 
     get knownNonResourceScripts()
     {
-        var knownScripts = [];
-        for (var id in this._scriptIdMap) {
-            var script = this._scriptIdMap[id];
+        let knownScripts = [];
+        for (let script of this._scriptIdMap.values()) {
             if (script.resource)
                 continue;
             if (script.url && script.url.startsWith("__WebInspector"))
@@ -334,16 +335,20 @@
             return;
 
         if (breakpoint.url) {
-            var urlBreakpoints = this._breakpointURLMap[breakpoint.url];
-            if (!urlBreakpoints)
-                urlBreakpoints = this._breakpointURLMap[breakpoint.url] = [];
+            let urlBreakpoints = this._breakpointURLMap.get(breakpoint.url);
+            if (!urlBreakpoints) {
+                urlBreakpoints = [];
+                this._breakpointURLMap.set(breakpoint.url, urlBreakpoints);
+            }
             urlBreakpoints.push(breakpoint);
         }
 
         if (breakpoint.scriptIdentifier) {
-            var scriptIdentifierBreakpoints = this._breakpointScriptIdentifierMap[breakpoint.scriptIdentifier];
-            if (!scriptIdentifierBreakpoints)
-                scriptIdentifierBreakpoints = this._breakpointScriptIdentifierMap[breakpoint.scriptIdentifier] = [];
+            let scriptIdentifierBreakpoints = this._breakpointScriptIdentifierMap.get(breakpoint.scriptIdentifier);
+            if (!scriptIdentifierBreakpoints) {
+                scriptIdentifierBreakpoints = [];
+                this._breakpointScriptIdentifierMap.set(breakpoint.scriptIdentifier, scriptIdentifierBreakpoints);
+            }
             scriptIdentifierBreakpoints.push(breakpoint);
         }
 
@@ -376,20 +381,20 @@
             this._removeBreakpoint(breakpoint);
 
         if (breakpoint.url) {
-            var urlBreakpoints = this._breakpointURLMap[breakpoint.url];
+            let urlBreakpoints = this._breakpointURLMap.get(breakpoint.url);
             if (urlBreakpoints) {
                 urlBreakpoints.remove(breakpoint);
                 if (!urlBreakpoints.length)
-                    delete this._breakpointURLMap[breakpoint.url];
+                    this._breakpointURLMap.delete(breakpoint.url);
             }
         }
 
         if (breakpoint.scriptIdentifier) {
-            var scriptIdentifierBreakpoints = this._breakpointScriptIdentifierMap[breakpoint.scriptIdentifier];
+            let scriptIdentifierBreakpoints = this._breakpointScriptIdentifierMap.get(breakpoint.scriptIdentifier);
             if (scriptIdentifierBreakpoints) {
                 scriptIdentifierBreakpoints.remove(breakpoint);
                 if (!scriptIdentifierBreakpoints.length)
-                    delete this._breakpointScriptIdentifierMap[breakpoint.scriptIdentifier];
+                    this._breakpointScriptIdentifierMap.delete(breakpoint.scriptIdentifier);
             }
         }
 
@@ -404,7 +409,7 @@
     {
         // Called from WebInspector.DebuggerObserver.
 
-        var breakpoint = this._breakpointIdMap[breakpointIdentifier];
+        let breakpoint = this._breakpointIdMap.get(breakpointIdentifier);
         console.assert(breakpoint);
         if (!breakpoint)
             return;
@@ -431,8 +436,8 @@
         this._pauseReason = null;
         this._pauseData = null;
 
-        this._scriptIdMap = {};
-        this._scriptURLMap = {};
+        this._scriptIdMap.clear();
+        this._scriptURLMap.clear();
 
         this._ignoreBreakpointDisplayLocationDidChangeEvent = true;
 
@@ -512,23 +517,26 @@
     scriptDidParse(scriptIdentifier, url, isContentScript, startLine, startColumn, endLine, endColumn, sourceMapURL)
     {
         // Don't add the script again if it is already known.
-        if (this._scriptIdMap[scriptIdentifier]) {
-            console.assert(this._scriptIdMap[scriptIdentifier].url ="" (url || null));
-            console.assert(this._scriptIdMap[scriptIdentifier].range.startLine === startLine);
-            console.assert(this._scriptIdMap[scriptIdentifier].range.startColumn === startColumn);
-            console.assert(this._scriptIdMap[scriptIdentifier].range.endLine === endLine);
-            console.assert(this._scriptIdMap[scriptIdentifier].range.endColumn === endColumn);
+        if (this._scriptIdMap.has(scriptIdentifier)) {
+            const script = this._scriptIdMap.get(scriptIdentifier);
+            console.assert(script.url ="" (url || null));
+            console.assert(script.range.startLine === startLine);
+            console.assert(script.range.startColumn === startColumn);
+            console.assert(script.range.endLine === endLine);
+            console.assert(script.range.endColumn === endColumn);
             return;
         }
 
         var script = new WebInspector.Script(scriptIdentifier, new WebInspector.TextRange(startLine, startColumn, endLine, endColumn), url, isContentScript, sourceMapURL);
 
-        this._scriptIdMap[scriptIdentifier] = script;
+        this._scriptIdMap.set(scriptIdentifier, script);
 
         if (script.url) {
-            var scripts = this._scriptURLMap[script.url];
-            if (!scripts)
-                scripts = this._scriptURLMap[script.url] = [];
+            let scripts = this._scriptURLMap.get(script.url);
+            if (!scripts) {
+                scripts = [];
+                this._scriptURLMap.set(script.url, scripts);
+            }
             scripts.push(script);
         }
 
@@ -554,7 +562,7 @@
 
     _sourceCodeLocationFromPayload(payload)
     {
-        var script = this._scriptIdMap[payload.scriptId];
+        let script = this._scriptIdMap.get(payload.scriptId);
         console.assert(script);
         if (!script)
             return null;
@@ -657,7 +665,7 @@
             if (error)
                 return;
 
-            this._breakpointIdMap[breakpointIdentifier] = breakpoint;
+            this._breakpointIdMap.set(breakpointIdentifier, breakpoint);
 
             breakpoint.identifier = breakpointIdentifier;
 
@@ -718,7 +726,7 @@
             if (error)
                 console.error(error);
 
-            delete this._breakpointIdMap[breakpoint.identifier];
+            this._breakpointIdMap.delete(breakpoint.identifier);
 
             breakpoint.identifier = null;
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to