@@ -185,8 +185,8 @@ private static class destroy {
185185 $LAYOUT .byteOffset (MemoryLayout .PathElement .groupElement ("destroy" ));
186186
187187 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
190190 );
191191
192192 /**
@@ -213,13 +213,9 @@ static MethodHandle handle(SwiftAnyType ty) {
213213 * This includes deallocating the Swift managed memory for the object.
214214 */
215215 public static void destroy (SwiftAnyType type , MemorySegment object ) {
216- var fullTypeMetadata = fullTypeMetadata (type .$memorySegment ());
217- var wtable = valueWitnessTable (fullTypeMetadata );
218-
219216 var mh = destroy .handle (type );
220-
221217 try {
222- mh .invokeExact (object , wtable );
218+ mh .invokeExact (object , type . $memorySegment () );
223219 } catch (Throwable th ) {
224220 throw new AssertionError ("Failed to destroy '" + type + "' at " + object , th );
225221 }
@@ -246,7 +242,7 @@ private static class initializeWithCopy {
246242 /* -> */ ValueLayout .ADDRESS , // returns the destination object
247243 ValueLayout .ADDRESS , // destination
248244 ValueLayout .ADDRESS , // source
249- ValueLayout .ADDRESS // pointer to the witness table
245+ ValueLayout .ADDRESS // pointer to the type metadata
250246 );
251247
252248 /**
@@ -274,13 +270,10 @@ static MethodHandle handle(SwiftAnyType ty) {
274270 * Returns the dest object.
275271 */
276272 public static MemorySegment initializeWithCopy (SwiftAnyType type , MemorySegment dest , MemorySegment src ) {
277- var fullTypeMetadata = fullTypeMetadata (type .$memorySegment ());
278- var wtable = valueWitnessTable (fullTypeMetadata );
279-
280273 var mh = initializeWithCopy .handle (type );
281274
282275 try {
283- return (MemorySegment ) mh .invokeExact (dest , src , wtable );
276+ return (MemorySegment ) mh .invokeExact (dest , src , type . $memorySegment () );
284277 } catch (Throwable th ) {
285278 throw new AssertionError ("Failed to initializeWithCopy '" + type + "' (" + dest + ", " + src + ")" , th );
286279 }
0 commit comments