Skip to content

Commit feb042c

Browse files
WalterBrightThe Dlang Bot
authored andcommitted
convert bl_enlist() to Barray
1 parent 737d7c6 commit feb042c

1 file changed

Lines changed: 48 additions & 16 deletions

File tree

src/dmd/backend/blockopt.d

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,11 +1599,27 @@ private void blreturn()
15991599
}
16001600

16011601
/*****************************************
1602-
* Convert expression into a list.
1603-
* Construct the list in reverse, that is, so that the right-most
1604-
* expression occurs first in the list.
1602+
* Convert comma-expressions into an array of expressions.
16051603
*/
16061604

1605+
extern (D)
1606+
private void bl_enlist2(ref Barray!(elem*) elems, elem* e)
1607+
{
1608+
if (e)
1609+
{
1610+
elem_debug(e);
1611+
if (e.Eoper == OPcomma)
1612+
{
1613+
bl_enlist2(elems, e.EV.E1);
1614+
bl_enlist2(elems, e.EV.E2);
1615+
e.EV.E1 = e.EV.E2 = null;
1616+
el_free(e);
1617+
}
1618+
else
1619+
elems.push(e);
1620+
}
1621+
}
1622+
16071623
private list_t bl_enlist(elem *e)
16081624
{
16091625
list_t el = null;
@@ -1635,6 +1651,17 @@ private list_t bl_enlist(elem *e)
16351651
* Take a list of expressions and convert it back into an expression tree.
16361652
*/
16371653

1654+
extern (D)
1655+
private elem* bl_delist2(elem*[] elems)
1656+
{
1657+
elem* result = null;
1658+
foreach (e; elems)
1659+
{
1660+
result = el_combine(result, e);
1661+
}
1662+
return result;
1663+
}
1664+
16381665
private elem * bl_delist(list_t el)
16391666
{
16401667
elem *e = null;
@@ -2201,6 +2228,8 @@ private int el_anyframeptr(elem *e)
22012228

22022229
private void blassertsplit()
22032230
{
2231+
debug if (debugc) printf("blassertsplit()\n");
2232+
Barray!(elem*) elems;
22042233
for (block *b = startblock; b; b = b.Bnext)
22052234
{
22062235
/* Not sure of effect of jumping out of a try block
@@ -2211,7 +2240,9 @@ private void blassertsplit()
22112240
if (b.BC == BCexit)
22122241
continue;
22132242

2214-
list_t bel = list_reverse(bl_enlist(b.Belem));
2243+
elems.reset();
2244+
bl_enlist2(elems, b.Belem);
2245+
auto earray = elems[];
22152246
L1:
22162247
int dctor = 0;
22172248

@@ -2231,26 +2262,23 @@ private void blassertsplit()
22312262
continue;
22322263
}
22332264
else if (e.Eoper == OPdctor)
2234-
++dctor;
2265+
++dctor;
22352266
else if (e.Eoper == OPddtor)
2236-
--dctor;
2267+
--dctor;
22372268
break;
22382269
}
22392270
return dctor;
22402271
}
22412272

2242-
foreach (el; ListRange(bel))
2273+
foreach (i, e; earray)
22432274
{
2244-
elem *e = list_elem(el);
2245-
22462275
if (!(dctor == 0 && // don't split block between a dctor..ddtor pair
22472276
e.Eoper == OPoror && e.EV.E2.Eoper == OPcall && e.EV.E2.EV.E1.Eoper == OPvar))
22482277
{
22492278
accumDctor(e);
22502279
continue;
22512280
}
22522281
Symbol *f = e.EV.E2.EV.E1.EV.Vsym;
2253-
22542282
if (!(f.Sflags & SFLexit))
22552283
{
22562284
accumDctor(e);
@@ -2283,7 +2311,7 @@ private void blassertsplit()
22832311
bx = bxn;
22842312
}
22852313

2286-
el.ptr = cast(void *)e.EV.E1;
2314+
earray[i] = e.EV.E1;
22872315
e.EV.E1 = null;
22882316
e.EV.E2 = null;
22892317
el_free(e);
@@ -2297,9 +2325,8 @@ private void blassertsplit()
22972325
b.Bnext = b2;
22982326
b2.BC = b.BC;
22992327
b2.BS = b.BS;
2300-
list_t bex = list_next(el);
2301-
el.next = null;
2302-
b.Belem = bl_delist(list_reverse(bel));
2328+
2329+
b.Belem = bl_delist2(earray[0 .. i + 1]);
23032330

23042331
/* Transfer successors of b to b2.
23052332
* Fix up predecessors of successors to b2 to point to b2 instead of b
@@ -2324,12 +2351,17 @@ private void blassertsplit()
23242351
list_append(&bexit.Bpred, b);
23252352

23262353
b = b2;
2327-
bel = bex; // remainder of expression list goes into b2
2354+
earray = earray[i + 1 .. earray.length]; // rest of expressions go into b2
2355+
debug if (debugc)
2356+
{
2357+
printf(" split off assert\n");
2358+
}
23282359
go.changes++;
23292360
goto L1;
23302361
}
2331-
b.Belem = bl_delist(list_reverse(bel));
2362+
b.Belem = bl_delist2(earray);
23322363
}
2364+
elems.dtor();
23332365
}
23342366

23352367
} //!SPP

0 commit comments

Comments
 (0)