Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Rename memory_manager() to GetMemoryManager() #478

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
Dec 13, 2023
Merged
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion common/type_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ class TypeFactory {
public:
virtual ~TypeFactory() = default;

virtual MemoryManagerRef memory_manager() const = 0;
// Returns a `MemoryManagerRef` which is used to manage memory for internal
// data structures as well as created types.
virtual MemoryManagerRef GetMemoryManager() const = 0;

// Creates a `ListType` whose element type is `element`. Requires that
// `element` is a valid element type for lists.
Expand Down
5 changes: 5 additions & 0 deletions common/type_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "absl/base/attributes.h"
#include "absl/status/statusor.h"
#include "absl/strings/string_view.h"
#include "common/memory.h"
#include "common/type.h"

namespace cel {
Expand All @@ -31,6 +32,10 @@ class TypeProvider {
public:
virtual ~TypeProvider() = default;

// Returns a `MemoryManagerRef` which is used to manage memory for the type
// provider itself and its internal data structures.
virtual MemoryManagerRef GetMemoryManager() const = 0;

// `FindType` find the type corresponding to name `name`.
virtual absl::StatusOr<TypeView> FindType(
absl::string_view name, Type& scratch ABSL_ATTRIBUTE_LIFETIME_BOUND) = 0;
Expand Down
8 changes: 4 additions & 4 deletions common/types/thread_compatible_type_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ ListType ThreadCompatibleTypeFactory::CreateListTypeImpl(TypeView element) {
list_type != list_types_.end()) {
return list_type->second;
}
ListType list_type(memory_manager(), Type(element));
ListType list_type(GetMemoryManager(), Type(element));
return list_types_.insert({list_type.element(), list_type}).first->second;
}

Expand All @@ -38,7 +38,7 @@ MapType ThreadCompatibleTypeFactory::CreateMapTypeImpl(TypeView key,
map_type != map_types_.end()) {
return map_type->second;
}
MapType map_type(memory_manager(), Type(key), Type(value));
MapType map_type(GetMemoryManager(), Type(key), Type(value));
return map_types_
.insert({std::make_pair(map_type.key(), map_type.value()), map_type})
.first->second;
Expand All @@ -50,7 +50,7 @@ StructType ThreadCompatibleTypeFactory::CreateStructTypeImpl(
struct_type != struct_types_.end()) {
return struct_type->second;
}
StructType struct_type(memory_manager(), name);
StructType struct_type(GetMemoryManager(), name);
return struct_types_.insert({struct_type.name(), struct_type}).first->second;
}

Expand All @@ -61,7 +61,7 @@ OpaqueType ThreadCompatibleTypeFactory::CreateOpaqueTypeImpl(
opaque_type != opaque_types_.end()) {
return opaque_type->second;
}
OpaqueType opaque_type(memory_manager(), name, parameters);
OpaqueType opaque_type(GetMemoryManager(), name, parameters);
return opaque_types_
.insert({OpaqueTypeKey{.name = opaque_type.name(),
.parameters = opaque_type.parameters()},
Expand Down
2 changes: 1 addition & 1 deletion common/types/thread_compatible_type_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ThreadCompatibleTypeFactory final : public TypeFactory {
explicit ThreadCompatibleTypeFactory(MemoryManagerRef memory_manager)
: memory_manager_(memory_manager) {}

MemoryManagerRef memory_manager() const override { return memory_manager_; }
MemoryManagerRef GetMemoryManager() const override { return memory_manager_; }

private:
ListType CreateListTypeImpl(TypeView element) override;
Expand Down
8 changes: 4 additions & 4 deletions common/types/thread_safe_type_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ ListType ThreadSafeTypeFactory::CreateListTypeImpl(TypeView element) {
return list_type->second;
}
}
ListType list_type(memory_manager(), Type(element));
ListType list_type(GetMemoryManager(), Type(element));
absl::WriterMutexLock lock(&list_types_mutex_);
return list_types_.insert({list_type.element(), list_type}).first->second;
}
Expand All @@ -45,7 +45,7 @@ MapType ThreadSafeTypeFactory::CreateMapTypeImpl(TypeView key, TypeView value) {
return map_type->second;
}
}
MapType map_type(memory_manager(), Type(key), Type(value));
MapType map_type(GetMemoryManager(), Type(key), Type(value));
absl::WriterMutexLock lock(&map_types_mutex_);
return map_types_
.insert({std::make_pair(map_type.key(), map_type.value()), map_type})
Expand All @@ -60,7 +60,7 @@ StructType ThreadSafeTypeFactory::CreateStructTypeImpl(absl::string_view name) {
return struct_type->second;
}
}
StructType struct_type(memory_manager(), name);
StructType struct_type(GetMemoryManager(), name);
absl::WriterMutexLock lock(&struct_types_mutex_);
return struct_types_.insert({struct_type.name(), struct_type}).first->second;
}
Expand All @@ -80,7 +80,7 @@ OpaqueType ThreadSafeTypeFactory::CreateOpaqueTypeImpl(
return opaque_type->second;
}
}
OpaqueType opaque_type(memory_manager(), name, parameters);
OpaqueType opaque_type(GetMemoryManager(), name, parameters);
absl::WriterMutexLock lock(&opaque_types_mutex_);
return opaque_types_
.insert({OpaqueTypeKey{.name = opaque_type.name(),
Expand Down
2 changes: 1 addition & 1 deletion common/types/thread_safe_type_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ThreadSafeTypeFactory final : public TypeFactory {
explicit ThreadSafeTypeFactory(MemoryManagerRef memory_manager)
: memory_manager_(memory_manager) {}

MemoryManagerRef memory_manager() const override { return memory_manager_; }
MemoryManagerRef GetMemoryManager() const override { return memory_manager_; }

private:
ListType CreateListTypeImpl(TypeView element) override;
Expand Down
8 changes: 4 additions & 4 deletions common/value.h
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,7 @@ class ListValueBuilder<Value> final : public ListValueBuilderInterface {
public:
ListValueBuilder(TypeFactory& type_factory ABSL_ATTRIBUTE_LIFETIME_BOUND,
TypeView element)
: ListValueBuilder(type_factory.memory_manager(),
: ListValueBuilder(type_factory.GetMemoryManager(),
type_factory.CreateListType(element)) {}

ListValueBuilder(MemoryManagerRef memory_manager, ListType type)
Expand Down Expand Up @@ -1198,7 +1198,7 @@ class MapValueBuilder<Value, V> final : public MapValueBuilderInterface {

MapValueBuilder(TypeFactory& type_factory ABSL_ATTRIBUTE_LIFETIME_BOUND,
TypeView key, value_view_type value)
: MapValueBuilder(type_factory.memory_manager(),
: MapValueBuilder(type_factory.GetMemoryManager(),
type_factory.CreateMapType(key, value)) {}

MapValueBuilder(MemoryManagerRef memory_manager, MapType type)
Expand Down Expand Up @@ -1244,7 +1244,7 @@ class MapValueBuilder<K, Value> final : public MapValueBuilderInterface {

MapValueBuilder(TypeFactory& type_factory ABSL_ATTRIBUTE_LIFETIME_BOUND,
key_view_type key, TypeView value)
: MapValueBuilder(type_factory.memory_manager(),
: MapValueBuilder(type_factory.GetMemoryManager(),
type_factory.CreateMapType(key, value)) {}

MapValueBuilder(MemoryManagerRef memory_manager, MapType type)
Expand Down Expand Up @@ -1284,7 +1284,7 @@ class MapValueBuilder<Value, Value> final : public MapValueBuilderInterface {
public:
MapValueBuilder(TypeFactory& type_factory ABSL_ATTRIBUTE_LIFETIME_BOUND,
TypeView key, TypeView value)
: MapValueBuilder(type_factory.memory_manager(),
: MapValueBuilder(type_factory.GetMemoryManager(),
type_factory.CreateMapType(key, value)) {}

MapValueBuilder(MemoryManagerRef memory_manager, MapType type)
Expand Down
6 changes: 6 additions & 0 deletions common/value_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ class ValueProvider {
public:
virtual ~ValueProvider() = default;

// Returns a `MemoryManagerRef` which is used to manage memory for the value
// provider itself, its internal data structures, as well as for builders. The
// builders are managed by the value provider's memory manager, but the values
// produced by the builders are managed by the value factory's memory manager.
virtual MemoryManagerRef GetMemoryManager() const = 0;

// `NewListValueBuilder` returns a new `ListValueBuilderInterface` for the
// corresponding `ListType` `type`.
virtual absl::StatusOr<Unique<ListValueBuilderInterface>> NewListValueBuilder(
Expand Down
2 changes: 1 addition & 1 deletion common/values/list_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ class ListValueBuilder final : public ListValueBuilderInterface {

ListValueBuilder(TypeFactory& type_factory ABSL_ATTRIBUTE_LIFETIME_BOUND,
element_view_type element)
: ListValueBuilder(type_factory.memory_manager(),
: ListValueBuilder(type_factory.GetMemoryManager(),
type_factory.CreateListType(element)) {}

ListValueBuilder(MemoryManagerRef memory_manager, ListType type)
Expand Down
2 changes: 1 addition & 1 deletion common/values/map_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ class MapValueBuilder final : public MapValueBuilderInterface {

MapValueBuilder(TypeFactory& type_factory ABSL_ATTRIBUTE_LIFETIME_BOUND,
key_view_type key, value_view_type value)
: MapValueBuilder(type_factory.memory_manager(),
: MapValueBuilder(type_factory.GetMemoryManager(),
type_factory.CreateMapType(key, value)) {}

MapValueBuilder(MemoryManagerRef memory_manager, MapType type)
Expand Down