@@ -26,8 +26,6 @@ import { alreadyAssignedPerfEntries } from './xhr-interceptor';
2626 * In overall, the algorithm to get this data takes the best fit for the span,
2727 * this means the closest performance resource timing to the span start/end
2828 * performance times is the returned value.
29- * @param xhrUrl
30- * @param span
3129 */
3230export function getXhrPerfomanceData (
3331 xhrUrl : string ,
@@ -50,9 +48,8 @@ export function getXhrPerfomanceData(
5048 * Those are possible because there might be more than two entries that pass the
5149 * filter.
5250 * Additionally, the returned array is sorted by the entries' `startTime` as
53- * getEntriesByType() already does it (https://developer.mozilla.org/en-US/docs/Web/API/Performance/getEntriesByType#Return_Value).
54- * @param xhrUrl
55- * @param span
51+ * getEntriesByType() already does it.
52+ * (https://developer.mozilla.org/en-US/docs/Web/API/Performance/getEntriesByType#Return_Value).
5653 */
5754export function getPerfSortedResourceEntries (
5855 xhrUrl : string ,
@@ -93,7 +90,7 @@ export function getPossiblePerfResourceEntries(
9390 possiblePerfEntries . push ( { mainRequest : entryI } ) ;
9491 // Compare every performance entry with the perfomance entries in front of
9592 // it. This is possible as the entries are sorted by the startTime. That
96- // way we to avoid comparing twice the entries and taking the wrong order.
93+ // way, we avoid comparing twice the entries and taking the wrong order.
9794 for ( let j = i + 1 ; j < filteredSortedPerfEntries . length ; j ++ ) {
9895 const entryJ = filteredSortedPerfEntries [ j ] ;
9996 if ( isPossibleCorsPair ( entryI , entryJ ) ) {
@@ -115,9 +112,6 @@ export function getPossiblePerfResourceEntries(
115112 * be the one with the minimum gap to the span start/end timings.
116113 * The performance resource timing entry with the minimum gap to the span
117114 * start/end timings points out that entry is the best fit for the span.
118- *
119- * @param perfEntries
120- * @param span
121115 */
122116function getBestPerfResourceTiming (
123117 perfEntries : XhrPerformanceResourceTiming [ ] ,
@@ -169,15 +163,12 @@ function isPerfEntryPartOfXhr(
169163 * start/end times.
170164 */
171165function isPossibleCorsPair (
172- entry1 : PerformanceResourceTiming ,
173- entry2 : PerformanceResourceTiming
166+ maybePreflight : PerformanceResourceTiming ,
167+ maybeMainRequest : PerformanceResourceTiming
174168) : boolean {
175- // To determine if the entries overlap, the minimum responseEnd should be
176- // less than the maximum startTime (e.g. entry1 with startTime = 1 and
177- // responseEnd = 3 and entry2 with startTime = 2 and responseEnd = 4, the
178- // minimum is 3 and the maximum is 2, this tells that the intervals overlap).
179- return (
180- Math . min ( entry1 . responseEnd , entry2 . responseEnd ) <
181- Math . max ( entry1 . startTime , entry2 . startTime )
182- ) ;
169+ // We can be sure that `maybePreflight` startTime is less than
170+ // `maybeMainRequest` startTime because of the sorting done by
171+ // `getEntriesByType`. Thus, to check the timings do not overlap, the
172+ // maybePreflight.respondeEnd must be less than maybeMainRequest.startTime.
173+ return maybePreflight . responseEnd < maybeMainRequest . startTime ;
183174}
0 commit comments