Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(917)

Unified Diff: third_party/WebKit/Source/devtools/front_end/timeline/TimelineIRModel.js

Issue 1729603002: DevTools: Extract SegmentedRange from TimelineIRModel to utilities.js (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/devtools/front_end/timeline/TimelineFlameChart.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/devtools/front_end/timeline/TimelineIRModel.js
diff --git a/third_party/WebKit/Source/devtools/front_end/timeline/TimelineIRModel.js b/third_party/WebKit/Source/devtools/front_end/timeline/TimelineIRModel.js
index 03483d9ef08285998b256320df71f3c978e18973..ffaf571796d8e357e9247d0f2950a740b6ef7160 100644
--- a/third_party/WebKit/Source/devtools/front_end/timeline/TimelineIRModel.js
+++ b/third_party/WebKit/Source/devtools/front_end/timeline/TimelineIRModel.js
@@ -82,7 +82,7 @@ WebInspector.TimelineIRModel.prototype = {
var animations = asyncEventsByGroup.get(groups.animation);
if (animations)
this._processAnimations(animations);
- var range = new WebInspector.SegmentedRange();
+ var range = new SegmentedRange();
range.appendRange(this._drags); // Drags take lower precedence than animation, as we can't detect them reliably.
range.appendRange(this._cssAnimations);
range.appendRange(this._scrolls);
@@ -129,7 +129,7 @@ WebInspector.TimelineIRModel.prototype = {
// FIXME: also process renderer fling events.
if (!flingStart)
break;
- this._scrolls.append(new WebInspector.Segment(flingStart.startTime, event.endTime, phases.Fling));
+ this._scrolls.append(new Segment(flingStart.startTime, event.endTime, phases.Fling));
flingStart = null;
break;
@@ -168,7 +168,7 @@ WebInspector.TimelineIRModel.prototype = {
this._drags.append(this._segmentForEvent(event, phases.Drag));
} else if (touchStart) {
firstTouchMove = event;
- this._responses.append(new WebInspector.Segment(touchStart.startTime, event.endTime, phases.Response));
+ this._responses.append(new Segment(touchStart.startTime, event.endTime, phases.Response));
}
break;
@@ -199,7 +199,7 @@ WebInspector.TimelineIRModel.prototype = {
case eventTypes.MouseWheel:
// Do not consider first MouseWheel as trace viewer's implementation does -- in case of MouseWheel it's not really special.
if (mouseWheel && canMerge(thresholdsMs.mouse, mouseWheel, event))
- this._scrolls.append(new WebInspector.Segment(mouseWheel.endTime, event.startTime, phases.Scroll));
+ this._scrolls.append(new Segment(mouseWheel.endTime, event.startTime, phases.Scroll));
this._scrolls.append(this._segmentForEvent(event, phases.Scroll));
mouseWheel = event;
break;
@@ -230,15 +230,15 @@ WebInspector.TimelineIRModel.prototype = {
/**
* @param {!WebInspector.TracingModel.AsyncEvent} event
* @param {!WebInspector.TimelineIRModel.Phases} phase
- * @return {!WebInspector.Segment}
+ * @return {!Segment}
*/
_segmentForEvent: function(event, phase)
{
- return new WebInspector.Segment(event.startTime, event.endTime, phase);
+ return new Segment(event.startTime, event.endTime, phase);
},
/**
- * @return {!Array<!WebInspector.Segment>}
+ * @return {!Array<!Segment>}
*/
interactionRecords: function()
{
@@ -250,15 +250,15 @@ WebInspector.TimelineIRModel.prototype = {
var thresholdsMs = WebInspector.TimelineIRModel._mergeThresholdsMs;
this._segments = [];
- this._drags = new WebInspector.SegmentedRange(merge.bind(null, thresholdsMs.mouse));
- this._cssAnimations = new WebInspector.SegmentedRange(merge.bind(null, thresholdsMs.animation));
- this._responses = new WebInspector.SegmentedRange(merge.bind(null, 0));
- this._scrolls = new WebInspector.SegmentedRange(merge.bind(null, thresholdsMs.animation));
+ this._drags = new SegmentedRange(merge.bind(null, thresholdsMs.mouse));
+ this._cssAnimations = new SegmentedRange(merge.bind(null, thresholdsMs.animation));
+ this._responses = new SegmentedRange(merge.bind(null, 0));
+ this._scrolls = new SegmentedRange(merge.bind(null, thresholdsMs.animation));
/**
* @param {number} threshold
- * @param {!WebInspector.Segment} first
- * @param {!WebInspector.Segment} second
+ * @param {!Segment} first
+ * @param {!Segment} second
*/
function merge(threshold, first, second)
{
@@ -283,111 +283,3 @@ WebInspector.TimelineIRModel.prototype = {
}
};
-/**
- * @constructor
- * @param {(function(!WebInspector.Segment, !WebInspector.Segment): ?WebInspector.Segment)=} mergeCallback
- */
-WebInspector.SegmentedRange = function(mergeCallback)
-{
- /** @type {!Array<!WebInspector.Segment>} */
- this._segments = [];
- this._mergeCallback = mergeCallback;
-}
-
-/**
- * @constructor
- * @param {number} begin
- * @param {number} end
- * @param {*} data
- */
-WebInspector.Segment = function(begin, end, data)
-{
- if (begin > end)
- console.assert(false, "Invalid segment");
- this.begin = begin;
- this.end = end;
- this.data = data;
-}
-
-WebInspector.Segment.prototype = {
- /**
- * @param {!WebInspector.Segment} that
- * @return {boolean}
- */
- intersects: function(that)
- {
- return this.begin < that.end && that.begin < this.end;
- }
-};
-
-WebInspector.SegmentedRange.prototype = {
- /**
- * @param {!WebInspector.Segment} newSegment
- */
- append: function(newSegment)
- {
- // 1. Find the proper insertion point for new segment
- var startIndex = this._segments.lowerBound(newSegment, (a, b) => a.begin - b.begin);
- var endIndex = startIndex;
- var merged = null;
- if (startIndex > 0) {
- // 2. Try mering the preceding segment
- var precedingSegment = this._segments[startIndex - 1];
- merged = this._tryMerge(precedingSegment, newSegment);
- if (merged) {
- --startIndex;
- newSegment = merged;
- } else if (this._segments[startIndex - 1].end >= newSegment.begin) {
- // 2a. If merge failed and segments overlap, adjust preceding segment.
- // If an old segment entirely contains new one, split it in two.
- if (newSegment.end < precedingSegment.end)
- this._segments.splice(startIndex, 0, new WebInspector.Segment(newSegment.end, precedingSegment.end, precedingSegment.data));
- precedingSegment.end = newSegment.begin;
- }
- }
- // 3. Consume all segments that are entirely covered by the new one.
- while (endIndex < this._segments.length && this._segments[endIndex].end <= newSegment.end)
- ++endIndex;
- // 4. Merge or adjust the succeeding segment if it overlaps.
- if (endIndex < this._segments.length) {
- merged = this._tryMerge(newSegment, this._segments[endIndex]);
- if (merged) {
- endIndex++;
- newSegment = merged;
- } else if (newSegment.intersects(this._segments[endIndex]))
- this._segments[endIndex].begin = newSegment.end;
- }
- this._segments.splice(startIndex, endIndex - startIndex, newSegment);
- },
-
- /**
- * @param {!WebInspector.SegmentedRange} that
- */
- appendRange: function(that)
- {
- that.segments().forEach(segment => this.append(segment));
- },
-
- /**
- * @return {!Array<!WebInspector.Segment>}
- */
- segments: function()
- {
- return this._segments;
- },
-
- /**
- * @param {!WebInspector.Segment} first
- * @param {!WebInspector.Segment} second
- * @return {?WebInspector.Segment}
- */
- _tryMerge: function(first, second)
- {
- var merged = this._mergeCallback && this._mergeCallback(first, second);
- if (!merged)
- return null;
- merged.begin = first.begin;
- merged.end = Math.max(first.end, second.end);
- return merged;
- }
-}
« no previous file with comments | « third_party/WebKit/Source/devtools/front_end/timeline/TimelineFlameChart.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698