File tree 2 files changed +30
-1
lines changed
2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -961,7 +961,7 @@ class RefCounts {
961
961
bool isUniquelyReferenced () const {
962
962
auto bits = refCounts.load (SWIFT_MEMORY_ORDER_CONSUME);
963
963
if (bits.hasSideTable ())
964
- return false ; // FIXME: implement side table path if useful
964
+ return bits. getSideTable ()-> isUniquelyReferenced ();
965
965
966
966
assert (!bits.getIsDeiniting ());
967
967
return bits.isUniquelyReferenced ();
@@ -1384,6 +1384,10 @@ class HeapObjectSideTableEntry {
1384
1384
return refCounts.getCount ();
1385
1385
}
1386
1386
1387
+ bool isUniquelyReferenced () const {
1388
+ return refCounts.isUniquelyReferenced ();
1389
+ }
1390
+
1387
1391
bool isUniquelyReferencedOrPinned () const {
1388
1392
return refCounts.isUniquelyReferencedOrPinned ();
1389
1393
}
Original file line number Diff line number Diff line change @@ -36,6 +36,31 @@ tests.test("_isUnique/NativeObject") {
36
36
expectFalse ( _isUnique_native ( & b) )
37
37
}
38
38
39
+ tests. test ( " _isUnique/NativeObjectWithPreviousStrongRef " ) {
40
+ var a : Builtin . NativeObject = Builtin . castToNativeObject ( X ( ) )
41
+ expectTrue ( _isUnique_native ( & a) )
42
+ var b : Builtin . NativeObject ? = a
43
+ expectFalse ( _isUnique_native ( & a) )
44
+ b = nil
45
+ expectTrue ( _isUnique_native ( & a) )
46
+ }
47
+
48
+ tests. test ( " _isUnique/NativeObjectWithWeakRef " ) {
49
+ var a : Builtin . NativeObject = Builtin . castToNativeObject ( X ( ) )
50
+ expectTrue ( _isUnique_native ( & a) )
51
+ weak var b = a
52
+ expectTrue ( _isUnique_native ( & a) )
53
+ expectFalse ( _isUnique_native ( & b) )
54
+ }
55
+
56
+ tests. test ( " _isUnique/NativeObjectWithUnownedRef " ) {
57
+ var a : Builtin . NativeObject = Builtin . castToNativeObject ( X ( ) )
58
+ expectTrue ( _isUnique_native ( & a) )
59
+ unowned var b = a
60
+ expectTrue ( _isUnique_native ( & a) )
61
+ expectFalse ( _isUnique_native ( & b) )
62
+ }
63
+
39
64
tests. test ( " _isUniquelyReferenced/OptionalNativeObject " ) {
40
65
var a : Builtin . NativeObject ? = Builtin . castToNativeObject ( X ( ) )
41
66
StdlibUnittest . expectTrue ( _getBool ( Builtin . isUnique ( & a) ) )
You can’t perform that action at this time.
0 commit comments