lib/third_party/tracing/base/range_utils.js
function findEmptyRangesBetweenRanges(inRanges, opt_totalRange) {
    if (opt_totalRange && opt_totalRange.isEmpty)
      opt_totalRange = undefined;

    var emptyRanges = [];
    if (!inRanges.length) {
      if (opt_totalRange)
        emptyRanges.push(opt_totalRange);
      return emptyRanges;
    }

    inRanges = inRanges.slice();
    inRanges.sort(function(x, y) {
      return x.min - y.min;
    });
    if (opt_totalRange &&
        (opt_totalRange.min < inRanges[0].min)) {
      emptyRanges.push(tr.b.Range.fromExplicitRange(
          opt_totalRange.min, inRanges[0].min));
    }

    inRanges.forEach(function(range, index) {
      for (var otherIndex = 0; otherIndex < inRanges.length; ++otherIndex) {
        if (index === otherIndex)
          continue;
        var other = inRanges[otherIndex];

        if (other.min > range.max) {
          // |inRanges| is sorted, so |other| is the first range after |range|,
          // and there is an empty range between them.
          emptyRanges.push(tr.b.Range.fromExplicitRange(
              range.max, other.min));
          return;
        }
        // Otherwise, |other| starts before |range| ends, so |other| might
        // possibly contain the end of |range|.

        if (other.max > range.max) {
          // |other| does contain the end of |range|, so no empty range starts
          // at the end of this |range|.
          return;
        }
      }
      if (opt_totalRange && (range.max < opt_totalRange.max)) {
        emptyRanges.push(tr.b.Range.fromExplicitRange(
            range.max, opt_totalRange.max));
      }
    });
    return emptyRanges;
  }
function findEmptyRangesBetweenRanges(inRanges, opt_totalRange) {
    if (opt_totalRange && opt_totalRange.isEmpty)
      opt_totalRange = undefined;

    var emptyRanges = [];
    if (!inRanges.length) {
      if (opt_totalRange)
        emptyRanges.push(opt_totalRange);
      return emptyRanges;
    }

    inRanges = inRanges.slice();
    inRanges.sort(function(x, y) {
      return x.min - y.min;
    });
    if (opt_totalRange &&
        (opt_totalRange.min < inRanges[0].min)) {
      emptyRanges.push(tr.b.Range.fromExplicitRange(
          opt_totalRange.min, inRanges[0].min));
    }

    inRanges.forEach(function(range, index) {
      for (var otherIndex = 0; otherIndex < inRanges.length; ++otherIndex) {
        if (index === otherIndex)
          continue;
        var other = inRanges[otherIndex];

        if (other.min > range.max) {
          // |inRanges| is sorted, so |other| is the first range after |range|,
          // and there is an empty range between them.
          emptyRanges.push(tr.b.Range.fromExplicitRange(
              range.max, other.min));
          return;
        }
        // Otherwise, |other| starts before |range| ends, so |other| might
        // possibly contain the end of |range|.

        if (other.max > range.max) {
          // |other| does contain the end of |range|, so no empty range starts
          // at the end of this |range|.
          return;
        }
      }
      if (opt_totalRange && (range.max < opt_totalRange.max)) {
        emptyRanges.push(tr.b.Range.fromExplicitRange(
            range.max, opt_totalRange.max));
      }
    });
    return emptyRanges;
  }
function findEmptyRangesBetweenRanges ( inRanges , opt_totalRange ) { if ( opt_totalRange && opt_totalRange . isEmpty ) opt_totalRange = undefined ; var emptyRanges = [ ] ; if ( ! inRanges . length ) { if ( opt_totalRange ) emptyRanges . push ( opt_totalRange ) ; return emptyRanges ; } inRanges = inRanges . slice ( ) ; inRanges . sort ( function ( x , y ) { return x . min - y . min ; } ) ; if ( opt_totalRange && ( opt_totalRange . min < inRanges [ 0 ] . min ) ) { emptyRanges . push ( tr . b . Range . fromExplicitRange ( opt_totalRange . min , inRanges [ 0 ] . min ) ) ; } inRanges . forEach ( function ( range , index ) { for ( var otherIndex = 0 ; otherIndex < inRanges . length ; ++ otherIndex ) { if ( index === otherIndex ) continue ; var other = inRanges [ otherIndex ] ; if ( other . min > range . max ) { // |inRanges| is sorted, so |other| is the first range after |range|, // and there is an empty range between them. emptyRanges . push ( tr . b . Range . fromExplicitRange ( range . max , other . min ) ) ; return ; } // Otherwise, |other| starts before |range| ends, so |other| might // possibly contain the end of |range|. if ( other . max > range . max ) { // |other| does contain the end of |range|, so no empty range starts // at the end of this |range|. return ; } } if ( opt_totalRange && ( range . max < opt_totalRange . max ) ) { emptyRanges . push ( tr . b . Range . fromExplicitRange ( range . max , opt_totalRange . max ) ) ; } } ) ; return emptyRanges ; }
Pass in |opt_totalRange| in order to find empty ranges before the first of |inRanges| and after the last of |inRanges|.
Pass in |opt_totalRange| in order to find empty ranges before the first of |inRanges| and after the last of |inRanges| .