Skip to content

Commit

Permalink
Update type cache to return views
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 588915198
  • Loading branch information
jcking authored and copybara-github committed Dec 7, 2023
1 parent 3345110 commit 76cdde6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
8 changes: 4 additions & 4 deletions common/type_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class ThreadSafeTypeFactory final : public TypeFactory {
if (auto opaque_type =
ProcessLocalTypeCache::Get()->FindOpaqueType(name, parameters);
opaque_type.has_value()) {
return *opaque_type;
return OpaqueType(*opaque_type);
}
{
absl::ReaderMutexLock lock(&opaque_types_mutex_);
Expand Down Expand Up @@ -215,7 +215,7 @@ bool IsValidMapKeyType(TypeView type) {
ListType TypeFactory::CreateListType(TypeView element) {
if (auto list_type = ProcessLocalTypeCache::Get()->FindListType(element);
list_type.has_value()) {
return *list_type;
return ListType(*list_type);
}
return CreateListTypeImpl(element);
}
Expand All @@ -224,7 +224,7 @@ MapType TypeFactory::CreateMapType(TypeView key, TypeView value) {
ABSL_DCHECK(IsValidMapKeyType(key)) << key;
if (auto map_type = ProcessLocalTypeCache::Get()->FindMapType(key, value);
map_type.has_value()) {
return *map_type;
return MapType(*map_type);
}
return CreateMapTypeImpl(key, value);
}
Expand All @@ -240,7 +240,7 @@ OpaqueType TypeFactory::CreateOpaqueType(
if (auto opaque_type =
ProcessLocalTypeCache::Get()->FindOpaqueType(name, parameters);
opaque_type.has_value()) {
return *opaque_type;
return OpaqueType(*opaque_type);
}
return CreateOpaqueTypeImpl(name, parameters);
}
Expand Down
8 changes: 4 additions & 4 deletions common/types/type_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const ProcessLocalTypeCache* ProcessLocalTypeCache::Get() {
return &*type_cache;
}

absl::optional<ListType> ProcessLocalTypeCache::FindListType(
absl::optional<ListTypeView> ProcessLocalTypeCache::FindListType(
TypeView element) const {
if (auto list_type = list_types_.find(element);
list_type != list_types_.end()) {
Expand All @@ -57,7 +57,7 @@ SizedInputView<ListTypeView> ProcessLocalTypeCache::ListTypes() const {
return SizedInputView<ListTypeView>(list_types_, MapValueTransformer{});
}

absl::optional<MapType> ProcessLocalTypeCache::FindMapType(
absl::optional<MapTypeView> ProcessLocalTypeCache::FindMapType(
TypeView key, TypeView value) const {
if (auto map_type = map_types_.find(std::make_pair(key, value));
map_type != map_types_.end()) {
Expand All @@ -70,7 +70,7 @@ SizedInputView<MapTypeView> ProcessLocalTypeCache::MapTypes() const {
return SizedInputView<MapTypeView>(map_types_, MapValueTransformer{});
}

absl::optional<OpaqueType> ProcessLocalTypeCache::FindOpaqueType(
absl::optional<OpaqueTypeView> ProcessLocalTypeCache::FindOpaqueType(
absl::string_view name, const SizedInputView<TypeView>& parameters) const {
if (auto opaque_type = opaque_types_.find(
OpaqueTypeKeyView{.name = name, .parameters = parameters});
Expand All @@ -96,7 +96,7 @@ ProcessLocalTypeCache::ProcessLocalTypeCache() {
ABSL_DCHECK(dyn_dyn_map_type_.has_value());
auto opaque_type = FindOpaqueType(OptionalType::kName, {DynTypeView()});
ABSL_DCHECK(opaque_type.has_value());
dyn_optional_type_ = Cast<OptionalType>(*opaque_type);
dyn_optional_type_ = Cast<OptionalTypeView>(*opaque_type);
}

template <typename... Ts>
Expand Down
12 changes: 6 additions & 6 deletions common/types/type_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,15 @@ class ProcessLocalTypeCache final {
public:
ABSL_ATTRIBUTE_PURE_FUNCTION static const ProcessLocalTypeCache* Get();

absl::optional<ListType> FindListType(TypeView element) const;
absl::optional<ListTypeView> FindListType(TypeView element) const;

SizedInputView<ListTypeView> ListTypes() const;

absl::optional<MapType> FindMapType(TypeView key, TypeView value) const;
absl::optional<MapTypeView> FindMapType(TypeView key, TypeView value) const;

SizedInputView<MapTypeView> MapTypes() const;

absl::optional<OpaqueType> FindOpaqueType(
absl::optional<OpaqueTypeView> FindOpaqueType(
absl::string_view name, const SizedInputView<TypeView>& parameters) const;

SizedInputView<OpaqueTypeView> OpaqueTypes() const;
Expand Down Expand Up @@ -174,9 +174,9 @@ class ProcessLocalTypeCache final {
ListTypeCacheMap list_types_;
MapTypeCacheMap map_types_;
OpaqueTypeCacheMap opaque_types_;
absl::optional<ListType> dyn_list_type_;
absl::optional<MapType> dyn_dyn_map_type_;
absl::optional<OptionalType> dyn_optional_type_;
absl::optional<ListTypeView> dyn_list_type_;
absl::optional<MapTypeView> dyn_dyn_map_type_;
absl::optional<OptionalTypeView> dyn_optional_type_;
};

} // namespace cel::common_internal
Expand Down

0 comments on commit 76cdde6

Please sign in to comment.