302
303
getUnion(other: LineRangeSet): LineRangeSet {
304
>
if (this._normalizedRanges.length === 0) {
lineRange.ts
305
return other;
306
}
307
>
if (other._normalizedRanges.length === 0) {
lineRange.ts
308
return this;
309
}
311
>
const result: LineRange[] = [];
312
>
let i1 = 0;
313
>
let i2 = 0;
314
>
let current: LineRange | null = null;
315
>
while (i1 < this._normalizedRanges.length || i2 < other._normalizedRanges.length) {
316
>
let next: LineRange | null = null;
317
>
if (i1 < this._normalizedRanges.length && i2 < other._normalizedRanges.length) {
318
>
const lineRange1 = this._normalizedRanges[i1];
319
>
const lineRange2 = other._normalizedRanges[i2];
320
>
if (lineRange1.startLineNumber < lineRange2.startLineNumber) {
321
>
next = lineRange1;
322
>
i1++;
323
>
} else {
324
>
next = lineRange2;
325
>
i2++;
326
>
}
327
>
} else if (i1 < this._normalizedRanges.length) {
328
>
next = this._normalizedRanges[i1];
329
>
i1++;
330
>
} else {
331
next = other._normalizedRanges[i2];
332
i2++;
333
}
335
>
if (current === null) {
336
>
current = next;
337
>
} else {
338
>
if (current.endLineNumberExclusive >= next.startLineNumber) {
339
>
// merge
340
>
current = new LineRange(current.startLineNumber, Math.max(current.endLineNumberExclusive, next.endLineNumberExclusive));
341
>
} else {
342
>
// push
343
>
result.push(current);
344
>
current = next;
345
>
}
346
>
}
347
>
}
348
>
if (current !== null) {
349
>
result.push(current);
350
>
}
351
>
return new LineRangeSet(result);
352
>
}
353
354
/**