Skip to content

Prefer anonymous functions instead of member pointers here #11551

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 22, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions stdlib/public/runtime/Metadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,22 +613,19 @@ static void tuple_destroyArray(OpaqueValue *array, size_t n,

// The operation doesn't have to be initializeWithCopy, but they all
// have basically the same type.
typedef value_witness_types::initializeWithCopy
ValueWitnessTable::*forEachOperation;
typedef value_witness_types::initializeWithCopy forEachOperation;

/// Perform an operation for each field of two tuples.
static OpaqueValue *tuple_forEachField(OpaqueValue *destTuple,
OpaqueValue *srcTuple,
const Metadata *_metatype,
forEachOperation member) {
forEachOperation operation) {
auto &metatype = *(const TupleTypeMetadata*) _metatype;
for (size_t i = 0, e = metatype.NumElements; i != e; ++i) {
auto &eltInfo = metatype.getElement(i);
auto eltValueWitnesses = eltInfo.Type->getValueWitnesses();

OpaqueValue *destElt = eltInfo.findIn(destTuple);
OpaqueValue *srcElt = eltInfo.findIn(srcTuple);
(eltValueWitnesses->*member)(destElt, srcElt, eltInfo.Type);
operation(destElt, srcElt, eltInfo.Type);
}

return destTuple;
Expand Down Expand Up @@ -671,7 +668,9 @@ static OpaqueValue *tuple_initializeWithCopy(OpaqueValue *dest,

if (IsPOD) return tuple_memcpy(dest, src, metatype);
return tuple_forEachField(dest, src, metatype,
&ValueWitnessTable::initializeWithCopy);
[](OpaqueValue *dest, OpaqueValue *src, const Metadata *eltType) {
return eltType->vw_initializeWithCopy(dest, src);
});
}

/// Generic tuple value witness for 'initializeArrayWithCopy'.
Expand Down Expand Up @@ -709,7 +708,9 @@ static OpaqueValue *tuple_initializeWithTake(OpaqueValue *dest,

if (IsPOD) return tuple_memcpy(dest, src, metatype);
return tuple_forEachField(dest, src, metatype,
&ValueWitnessTable::initializeWithTake);
[](OpaqueValue *dest, OpaqueValue *src, const Metadata *eltType) {
return eltType->vw_initializeWithTake(dest, src);
});
}

/// Generic tuple value witness for 'initializeArrayWithTakeFrontToBack'.
Expand Down Expand Up @@ -774,7 +775,9 @@ static OpaqueValue *tuple_assignWithCopy(OpaqueValue *dest,

if (IsPOD) return tuple_memcpy(dest, src, metatype);
return tuple_forEachField(dest, src, metatype,
&ValueWitnessTable::assignWithCopy);
[](OpaqueValue *dest, OpaqueValue *src, const Metadata *eltType) {
return eltType->vw_assignWithCopy(dest, src);
});
}

/// Generic tuple value witness for 'assignWithTake'.
Expand All @@ -784,7 +787,9 @@ static OpaqueValue *tuple_assignWithTake(OpaqueValue *dest,
const Metadata *metatype) {
if (IsPOD) return tuple_memcpy(dest, src, metatype);
return tuple_forEachField(dest, src, metatype,
&ValueWitnessTable::assignWithTake);
[](OpaqueValue *dest, OpaqueValue *src, const Metadata *eltType) {
return eltType->vw_assignWithTake(dest, src);
});
}

/// Generic tuple value witness for 'initializeBufferWithCopyOfBuffer'.
Expand Down