@@ -44,22 +44,6 @@ irange_eq_bounds(IndexRange a, IndexRange b)
44
44
(irange_upper (a ) == irange_upper (b ));
45
45
}
46
46
47
- /* Comapre lossiness factor of two ranges */
48
- ir_cmp_lossiness
49
- irange_cmp_lossiness (IndexRange a , IndexRange b )
50
- {
51
- if (is_irange_lossy (a ) == is_irange_lossy (b ))
52
- return IR_EQ_LOSSINESS ;
53
-
54
- if (is_irange_lossy (a ))
55
- return IR_A_LOSSY ;
56
-
57
- if (is_irange_lossy (b ))
58
- return IR_B_LOSSY ;
59
-
60
- return IR_EQ_LOSSINESS ;
61
- }
62
-
63
47
64
48
/* Make union of two conjuncted ranges */
65
49
IndexRange
@@ -161,6 +145,10 @@ irange_union_internal(IndexRange first,
161
145
IndexRange second ,
162
146
List * * new_iranges )
163
147
{
148
+ /* Assert that both IndexRanges are valid */
149
+ Assert (is_irange_valid (first ));
150
+ Assert (is_irange_valid (second ));
151
+
164
152
/* Swap 'first' and 'second' if order is incorrect */
165
153
if (irange_lower (first ) > irange_lower (second ))
166
154
{
@@ -332,39 +320,48 @@ irange_list_intersection(List *a, List *b)
332
320
IndexRange ra = lfirst_irange (ca ),
333
321
rb = lfirst_irange (cb );
334
322
323
+ /* Assert that both IndexRanges are valid */
324
+ Assert (is_irange_valid (ra ));
325
+ Assert (is_irange_valid (rb ));
326
+
335
327
/* Only care about intersecting ranges */
336
328
if (iranges_intersect (ra , rb ))
337
329
{
338
- IndexRange intersect , last ;
330
+ IndexRange ir_intersection ;
331
+ bool glued_to_last = false;
339
332
340
333
/*
341
334
* Get intersection and try to "glue" it to
342
- * previous range , put it separately otherwise.
335
+ * last irange , put it separately otherwise.
343
336
*/
344
- intersect = irange_intersection_simple (ra , rb );
337
+ ir_intersection = irange_intersection_simple (ra , rb );
345
338
if (result != NIL )
346
339
{
347
- last = llast_irange (result );
348
- if (iranges_adjoin (last , intersect ) &&
349
- is_irange_lossy (last ) == is_irange_lossy (intersect ))
350
- {
351
- llast (result ) = alloc_irange (irange_union_simple (last , intersect ));
352
- }
353
- else
340
+ IndexRange last = llast_irange (result );
341
+
342
+ /* Test if we can glue 'last' and 'ir_intersection' */
343
+ if (irange_cmp_lossiness (last , ir_intersection ) == IR_EQ_LOSSINESS &&
344
+ iranges_adjoin (last , ir_intersection ))
354
345
{
355
- result = lappend_irange (result , intersect );
346
+ IndexRange ir_union = irange_union_simple (last , ir_intersection );
347
+
348
+ /* We allocate a new IndexRange for safety */
349
+ llast (result ) = alloc_irange (ir_union );
350
+
351
+ /* Successfully glued them */
352
+ glued_to_last = true;
356
353
}
357
354
}
358
- else
359
- {
360
- result = lappend_irange ( result , intersect );
361
- }
355
+
356
+ /* Append IndexRange if we couldn't glue it */
357
+ if (! glued_to_last )
358
+ result = lappend_irange ( result , ir_intersection );
362
359
}
363
360
364
361
/*
365
- * Fetch next ranges . We use upper bound of current range to determine
366
- * which lists to fetch, since lower bound of next range is greater (or
367
- * equal) to upper bound of current.
362
+ * Fetch next iranges . We use upper bound of current irange to
363
+ * determine which lists to fetch, since lower bound of next
364
+ * irange is greater (or equal) to upper bound of current.
368
365
*/
369
366
if (irange_upper (ra ) <= irange_upper (rb ))
370
367
ca = lnext (ca );
0 commit comments