Skip to content
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
14 changes: 7 additions & 7 deletions stdlib/public/Reflection/TypeRefBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ TypeRefBuilder::normalizeReflectionName(RemoteRef<char> reflectionName) {
if (!mangling.isSuccess()) {
return {};
}
return mangling.result();
return std::move(mangling.result());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I think this should be reverted, since it disables RVO

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is that RVO doesn't apply here, as this value is of type string, but the return type is Optional<string>. This change does not trigger the -Wpessimizing-move warning.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll restate that, I think RVO does happen here – for the Optional. This move applies to the value going inside of the Optional, not the Optional itself.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe this would be more clear if the code was explicit:

return Optional(std::move(…));

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, makes sense!

}
}

Expand Down Expand Up @@ -194,16 +194,16 @@ const TypeRef *TypeRefBuilder::lookupSuperclass(const TypeRef *TR) {

RemoteRef<FieldDescriptor>
TypeRefBuilder::getFieldTypeInfo(const TypeRef *TR) {
std::string MangledName;
const std::string *MangledName;
if (auto N = dyn_cast<NominalTypeRef>(TR))
MangledName = N->getMangledName();
MangledName = &N->getMangledName();
else if (auto BG = dyn_cast<BoundGenericTypeRef>(TR))
MangledName = BG->getMangledName();
MangledName = &BG->getMangledName();
else
return nullptr;

// Try the cache.
auto Found = FieldTypeInfoCache.find(MangledName);
auto Found = FieldTypeInfoCache.find(*MangledName);
if (Found != FieldTypeInfoCache.end())
return Found->second;

Expand All @@ -216,13 +216,13 @@ TypeRefBuilder::getFieldTypeInfo(const TypeRef *TR) {
continue;
auto CandidateMangledName = readTypeRef(FD, FD->MangledTypeName);
if (auto NormalizedName = normalizeReflectionName(CandidateMangledName))
FieldTypeInfoCache[*NormalizedName] = FD;
FieldTypeInfoCache[std::move(*NormalizedName)] = FD;
}

// Since we're done with the current ReflectionInfo, increment early in
// case we get a cache hit.
++FirstUnprocessedReflectionInfoIndex;
Found = FieldTypeInfoCache.find(MangledName);
Found = FieldTypeInfoCache.find(*MangledName);
if (Found != FieldTypeInfoCache.end())
return Found->second;
}
Expand Down