Skip to content

Commit eaafe33

Browse files
authored
Merge pull request swiftlang#15139 from gottesmm/pr-400a9ca07f4710ed248281e364eb49e11835d7de
Runtime: Do the bare minimum balancing for bridge casting at +0.
2 parents 2aa4869 + 0d7c42c commit eaafe33

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

stdlib/public/runtime/Casting.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2823,8 +2823,7 @@ static bool _dynamicCastClassToValueViaObjCBridgeable(
28232823
return _fail(src, srcType, targetType, flags);
28242824
}
28252825

2826-
// Unless we're always supposed to consume the input, retain the
2827-
// object because the witness takes it at +1.
2826+
// TODO: Avoid the retain here in +0 mode if the input is never consumed.
28282827
bool alwaysConsumeSrc = (flags & DynamicCastFlags::TakeOnSuccess) &&
28292828
(flags & DynamicCastFlags::DestroyOnFailure);
28302829
if (!alwaysConsumeSrc) {
@@ -2880,15 +2879,14 @@ static bool _dynamicCastClassToValueViaObjCBridgeable(
28802879
(HeapObject *)srcObject, (OpaqueValue *)optDestBuffer,
28812880
targetType, targetType, targetBridgeWitness);
28822881
}
2882+
SWIFT_CC_PLUSZERO_GUARD(swift_unknownRelease(srcObject));
28832883

28842884
// If we succeeded, take from the optional buffer into the
28852885
// destination buffer.
28862886
if (success) {
28872887
targetType->vw_initializeWithTake(dest, (OpaqueValue *)optDestBuffer);
28882888
}
28892889

2890-
// Unless we're always supposed to consume the input, release the
2891-
// input if we need to now.
28922890
if (!alwaysConsumeSrc && shouldDeallocateSource(success, flags)) {
28932891
swift_unknownRelease(srcObject);
28942892
}

0 commit comments

Comments
 (0)