Skip to content

swift_arrayAssignWithCopyBackToFront(________)

0x41c edited this page Feb 28, 2022 · 1 revision

swift_arrayAssignWithCopyBackToFront(_:_:_:_:)

The type UnsafeRawPointer in the case of the array function signatures actually represent OpaqueValue*. Until That is properly bridged over, it is what it is. Any.Type Represents the self parameter or Metadata. This follows the same principle. Until the proper Array metadata is bridged, we leave it be. This may not be the best solution so every suggestion is appreciated

@_silgen_name("swift_arrayAssignWithCopyBackToFront")
public func swift_arrayAssignWithCopyBackToFront(
    _ destination: UnsafeRawPointer,
    _ source: UnsafeRawPointer,
    _ count: Int,
    _ self: Any.Type
)

All the array functions are wrapping the singular function array_copy_operation. The array_copy_operation function acts as one size fits all for all initializing and copying functions for arrays. There are three things that determine the route that it takes to copy values or initialize them from one array to another. These are (1) The destination operation, (2) the source operation, and finally (3) the copy kind. Before explaining what they do, take note that the value passed in as self is the ValueWitnessTable that will be used for the operations.

What the destination operation determines is wether the ValueWitnessTable will be created or whether it will be copied into. These are determined by the c++ template values ArrayDest::Init, and ArrayDest::Assign respectively. The source operation determines how the data will be taken from the source object. This can be described with the C++ template types ArraySource::Copy and ArraySource::Take. Finally, the copy kind determines how the values from the source will be copied into the destination object. This is described with the types ArrayCopy::NoAlias, ArrayCopy::FrontToBack and ArrayCopy::BackToFront. What's interesting about this specifically, is that these will apply to both types of ValueWitnessTable and regular POD (Plain Old Data) types, but with functions like memmove and memcopy in the case of those other types. For the POD types, if the copy kind is ArrayCopy::NoAlias the function used is memcpy while the other two used memmove.

The functions for this are named in a way that allows you to specify the C++ template values. Here's an abstract representation of the initializing functions and the assigning functions:

`array(Init|Assign)With(Copy|Take)(NoAlias|FrontToBack|BackToFront)(arguments...)`

the arrayDestroy function does not follow these rules.

Using an already existant array and associated heap object, this assigns values from the source object object to the destination by copying them from the back of the object to the front. When the witness table is POD it uses memmove for the memory operation. When not POD, however, it will default to a witness function.

  • C++ Template Values:

    • ArrayDest::Assign
    • ArraySource::Copy
    • ArrayCopy::BackToFront

Parameters

  • destination: The destination heap object.
  • source: The source heap object.
  • count: Amount of items in the source object.
  • self: The destinations initialized metadata.
Types
Protocols
Global Typealiases
Global Functions
Clone this wiki locally