Skip to content

Commit 8b3aaf5

Browse files
committed
[Runtime] Compute end before looping over single payload ref count
1 parent 7c0203d commit 8b3aaf5

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

stdlib/public/runtime/BytecodeLayouts.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,12 +1414,14 @@ static void singlePayloadEnumSimpleAssignWithCopy(const Metadata *metadata,
14141414
if (srcTagBytes >= xiTagValues && destTagBytes >= xiTagValues) {
14151415
return;
14161416
} else if (destTagBytes >= xiTagValues) {
1417-
while (reader.layoutStr < (reader.layoutStr + refCountBytes)) {
1417+
const uint8_t *end = (reader.layoutStr + refCountBytes);
1418+
while (reader.layoutStr < end) {
14181419
handleSingleRefCountInitWithCopy(metadata, reader, addrOffset, dest, src);
14191420
}
14201421
return;
14211422
} else if (srcTagBytes >= xiTagValues) {
1422-
while (reader.layoutStr < (reader.layoutStr + refCountBytes)) {
1423+
const uint8_t *end = (reader.layoutStr + refCountBytes);
1424+
while (reader.layoutStr < end) {
14231425
handleSingleRefCountDestroy(metadata, reader, addrOffset, dest);
14241426
}
14251427
} else {
@@ -1448,12 +1450,14 @@ static void singlePayloadEnumFNAssignWithCopy(const Metadata *metadata,
14481450
if (SWIFT_UNLIKELY(srcTag == 0 && destTag == 0)) {
14491451
return;
14501452
} else if (srcTag == 0) {
1451-
while (reader.layoutStr < (reader.layoutStr + refCountBytes)) {
1453+
const uint8_t *end = (reader.layoutStr + refCountBytes);
1454+
while (reader.layoutStr < end) {
14521455
handleSingleRefCountInitWithCopy(metadata, reader, addrOffset, dest, src);
14531456
}
14541457
return;
14551458
} else if (destTag == 0) {
1456-
while (reader.layoutStr < (reader.layoutStr + refCountBytes)) {
1459+
const uint8_t *end = (reader.layoutStr + refCountBytes);
1460+
while (reader.layoutStr < end) {
14571461
handleSingleRefCountDestroy(metadata, reader, addrOffset, dest);
14581462
}
14591463
} else {
@@ -1482,12 +1486,14 @@ static void singlePayloadEnumFNResolvedAssignWithCopy(const Metadata *metadata,
14821486
if (SWIFT_UNLIKELY(srcTag == 0 && destTag == 0)) {
14831487
return;
14841488
} else if (srcTag == 0) {
1485-
while (reader.layoutStr < (reader.layoutStr + refCountBytes)) {
1489+
const uint8_t *end = (reader.layoutStr + refCountBytes);
1490+
while (reader.layoutStr < end) {
14861491
handleSingleRefCountInitWithCopy(metadata, reader, addrOffset, dest, src);
14871492
}
14881493
return;
14891494
} else if (destTag == 0) {
1490-
while (reader.layoutStr < (reader.layoutStr + refCountBytes)) {
1495+
const uint8_t *end = (reader.layoutStr + refCountBytes);
1496+
while (reader.layoutStr < end) {
14911497
handleSingleRefCountDestroy(metadata, reader, addrOffset, dest);
14921498
}
14931499
} else {
@@ -1541,12 +1547,14 @@ static void singlePayloadEnumGenericAssignWithCopy(const Metadata *metadata,
15411547
if (SWIFT_UNLIKELY(srcTag == 0 && destTag == 0)) {
15421548
return;
15431549
} else if (srcTag == 0) {
1544-
while (reader.layoutStr < (reader.layoutStr + refCountBytes)) {
1550+
const uint8_t *end = (reader.layoutStr + refCountBytes);
1551+
while (reader.layoutStr < end) {
15451552
handleSingleRefCountInitWithCopy(metadata, reader, addrOffset, dest, src);
15461553
}
15471554
return;
15481555
} else if (destTag == 0) {
1549-
while (reader.layoutStr < (reader.layoutStr + refCountBytes)) {
1556+
const uint8_t *end = (reader.layoutStr + refCountBytes);
1557+
while (reader.layoutStr < end) {
15501558
handleSingleRefCountDestroy(metadata, reader, addrOffset, dest);
15511559
}
15521560
} else {

0 commit comments

Comments
 (0)