[Runtime] Add layout string handling in swift_arrayAssignWithCopyFrontToBack

By using a specialize function, we only call through the witness table and fetch the layout string once for the whoe buffer, instead of once per element.
This commit is contained in:
Dario Rexin
2023-09-21 09:52:46 -07:00
parent d6c67f66c2
commit 56d0975668
5 changed files with 124 additions and 4 deletions

View File

@@ -111,6 +111,16 @@ static void array_copy_operation(OpaqueValue *dest, OpaqueValue *src,
// Call the witness to do the copy.
if (copyKind == ArrayCopy::NoAlias || copyKind == ArrayCopy::FrontToBack) {
if (self->hasLayoutString() && destOp == ArrayDest::Init &&
srcOp == ArraySource::Copy) {
return swift_generic_arrayInitWithCopy(dest, src, count, stride, self);
}
if (self->hasLayoutString() && destOp == ArrayDest::Assign &&
srcOp == ArraySource::Copy) {
return swift_generic_arrayAssignWithCopy(dest, src, count, stride, self);
}
auto copy = get_witness_function<destOp, srcOp>(wtable);
for (size_t i = 0; i < count; ++i) {
auto offset = i * stride;
@@ -125,10 +135,6 @@ static void array_copy_operation(OpaqueValue *dest, OpaqueValue *src,
assert(copyKind == ArrayCopy::BackToFront);
assert(count != 0);
if (self->hasLayoutString() && destOp == ArrayDest::Init && srcOp == ArraySource::Copy) {
return swift_generic_arrayInitWithCopy(dest, src, count, stride, self);
}
auto copy = get_witness_function<destOp, srcOp>(wtable);
size_t i = count;
do {