mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
[PyTorch] Avoid refcount bump in UnionType::canHoldType (#66693)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/66693 Passing a `TypePtr` by value causes an unnececssary refcount bump. We don't need to take ownership, so `const Type&` is all we need. I considered providing a compatibility shim that takes `const TypePtr&`, but doing so is dangerous because a copy is required to convert from a more specific pointer like `NoneTypePtr`. ghstack-source-id: 140737081 Test Plan: CI Reviewed By: suo Differential Revision: D31691869 fbshipit-source-id: f766ce3234a28771c2a9ca4c284eb3f96993a3d0
This commit is contained in:
committed by
Facebook GitHub Bot
parent
1db50505d5
commit
f65b4b7a4c
@ -111,7 +111,7 @@ void restoreAccurateTypeTags(const IValue& root, const TypePtr& type_tag) {
|
||||
case UnionType::Kind: {
|
||||
auto t = w.static_type->expect<UnionType>();
|
||||
if (t->containedTypes().size() == 2 &&
|
||||
t->canHoldType(NoneType::get())) {
|
||||
t->canHoldType(*NoneType::get())) {
|
||||
if (!w.value.isNone()) {
|
||||
auto inner = t->containedTypes()[0] != NoneType::get()
|
||||
? t->containedTypes()[0]
|
||||
|
Reference in New Issue
Block a user