@@ -185,8 +185,8 @@ private static class destroy {
185
185
$LAYOUT .byteOffset (MemoryLayout .PathElement .groupElement ("destroy" ));
186
186
187
187
static final FunctionDescriptor DESC = FunctionDescriptor .ofVoid (
188
- ValueLayout .ADDRESS , // witness table functions expect a pointer to self pointer
189
- ValueLayout .ADDRESS // pointer to the witness table
188
+ ValueLayout .ADDRESS , // pointer to self
189
+ ValueLayout .ADDRESS // pointer to the type metadata
190
190
);
191
191
192
192
/**
@@ -213,13 +213,9 @@ static MethodHandle handle(SwiftAnyType ty) {
213
213
* This includes deallocating the Swift managed memory for the object.
214
214
*/
215
215
public static void destroy (SwiftAnyType type , MemorySegment object ) {
216
- var fullTypeMetadata = fullTypeMetadata (type .$memorySegment ());
217
- var wtable = valueWitnessTable (fullTypeMetadata );
218
-
219
216
var mh = destroy .handle (type );
220
-
221
217
try {
222
- mh .invokeExact (object , wtable );
218
+ mh .invokeExact (object , type . $memorySegment () );
223
219
} catch (Throwable th ) {
224
220
throw new AssertionError ("Failed to destroy '" + type + "' at " + object , th );
225
221
}
@@ -246,7 +242,7 @@ private static class initializeWithCopy {
246
242
/* -> */ ValueLayout .ADDRESS , // returns the destination object
247
243
ValueLayout .ADDRESS , // destination
248
244
ValueLayout .ADDRESS , // source
249
- ValueLayout .ADDRESS // pointer to the witness table
245
+ ValueLayout .ADDRESS // pointer to the type metadata
250
246
);
251
247
252
248
/**
@@ -274,13 +270,10 @@ static MethodHandle handle(SwiftAnyType ty) {
274
270
* Returns the dest object.
275
271
*/
276
272
public static MemorySegment initializeWithCopy (SwiftAnyType type , MemorySegment dest , MemorySegment src ) {
277
- var fullTypeMetadata = fullTypeMetadata (type .$memorySegment ());
278
- var wtable = valueWitnessTable (fullTypeMetadata );
279
-
280
273
var mh = initializeWithCopy .handle (type );
281
274
282
275
try {
283
- return (MemorySegment ) mh .invokeExact (dest , src , wtable );
276
+ return (MemorySegment ) mh .invokeExact (dest , src , type . $memorySegment () );
284
277
} catch (Throwable th ) {
285
278
throw new AssertionError ("Failed to initializeWithCopy '" + type + "' (" + dest + ", " + src + ")" , th );
286
279
}
0 commit comments