Title: [122964] trunk/Source/WebCore
Revision
122964
Author
[email protected]
Date
2012-07-18 06:46:22 -0700 (Wed, 18 Jul 2012)

Log Message

Web Inspector: intern strings when processing timeline records
https://bugs.webkit.org/show_bug.cgi?id=91531

Reviewed by Pavel Feldman.

- added StringPool that is capable of interning strings;
- used it in TimelineModel to process all incoming records;

* inspector/front-end/TimelineModel.js:
(WebInspector.TimelineModel):
(WebInspector.TimelineModel.prototype._addRecord):
(WebInspector.TimelineModel.prototype.reset):
* inspector/front-end/utilities.js:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (122963 => 122964)


--- trunk/Source/WebCore/ChangeLog	2012-07-18 13:42:57 UTC (rev 122963)
+++ trunk/Source/WebCore/ChangeLog	2012-07-18 13:46:22 UTC (rev 122964)
@@ -1,3 +1,19 @@
+2012-07-17  Andrey Kosyakov  <[email protected]>
+
+        Web Inspector: intern strings when processing timeline records
+        https://bugs.webkit.org/show_bug.cgi?id=91531
+
+        Reviewed by Pavel Feldman.
+
+        - added StringPool that is capable of interning strings;
+        - used it in TimelineModel to process all incoming records;
+
+        * inspector/front-end/TimelineModel.js:
+        (WebInspector.TimelineModel):
+        (WebInspector.TimelineModel.prototype._addRecord):
+        (WebInspector.TimelineModel.prototype.reset):
+        * inspector/front-end/utilities.js:
+
 2012-07-18  Scott Graham  <[email protected]>
 
         Use cl to preprocess IDL for Chromium Windows generate_supplemental_dependency

Modified: trunk/Source/WebCore/inspector/front-end/TimelineModel.js (122963 => 122964)


--- trunk/Source/WebCore/inspector/front-end/TimelineModel.js	2012-07-18 13:42:57 UTC (rev 122963)
+++ trunk/Source/WebCore/inspector/front-end/TimelineModel.js	2012-07-18 13:46:22 UTC (rev 122964)
@@ -35,6 +35,7 @@
 WebInspector.TimelineModel = function()
 {
     this._records = [];
+    this._stringPool = new StringPool();
     this._minimumRecordTime = -1;
     this._maximumRecordTime = -1;
     this._collectionEnabled = false;
@@ -152,6 +153,7 @@
 
     _addRecord: function(record)
     {
+        this._stringPool.internObjectStrings(record);
         this._records.push(record);
         this._updateBoundaries(record);
         this.dispatchEventToListeners(WebInspector.TimelineModel.Events.RecordAdded, record);
@@ -214,6 +216,7 @@
     reset: function()
     {
         this._records = [];
+        this._stringPool.reset();
         this._minimumRecordTime = -1;
         this._maximumRecordTime = -1;
         this.dispatchEventToListeners(WebInspector.TimelineModel.Events.RecordsCleared);

Modified: trunk/Source/WebCore/inspector/front-end/utilities.js (122963 => 122964)


--- trunk/Source/WebCore/inspector/front-end/utilities.js	2012-07-18 13:42:57 UTC (rev 122963)
+++ trunk/Source/WebCore/inspector/front-end/utilities.js	2012-07-18 13:46:22 UTC (rev 122964)
@@ -709,3 +709,59 @@
         this._map = {};
     }
 };
+
+
+/**
+ * @constructor
+ */
+function StringPool()
+{
+    this.reset();
+}
+
+StringPool.prototype = {
+    /**
+     * @param {string} string
+     * @return {string}
+     */
+    intern: function(string)
+    {
+        // Do not mess with setting __proto__ to anything but null, just handle it explicitly.
+        if (string === "__proto__")
+            return "__proto__";
+        var result = this._strings[string];
+        if (result === undefined) {
+            this._strings[string] = string;
+            result = string;
+        }
+        return result;
+    },
+
+    reset: function()
+    {
+        this._strings = Object.create(null);
+    },
+
+    /**
+     * @param {Object} obj
+     * @param {number=} depthLimit
+     */
+    internObjectStrings: function(obj, depthLimit)
+    {
+        if (typeof depthLimit !== "number")
+            depthLimit = 100;
+        else if (--depthLimit < 0)
+            throw "recursion depth limit reached in StringPool.deepIntern(), perhaps attempting to traverse cyclical references?";
+
+        for (var field in obj) {
+            switch (typeof obj[field]) {
+            case "string":
+                obj[field] = this.intern(obj[field]);
+                break;
+            case "object":
+                this.internObjectStrings(obj[field], depthLimit);
+                break;
+            }
+        }
+    }
+}
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to