Skip to content

Commit

Permalink
move and pass by reference for shared pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
ikbuibui committed Jul 29, 2024
1 parent f7c108c commit 2867117
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion redGrapes/SchedulerDescription.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace redGrapes
using Key = TTag;
using ValueType = TScheduler;

SchedulerDescription(std::shared_ptr<TScheduler> scheduler, TTag = DefaultTag{}) : scheduler{scheduler}
SchedulerDescription(std::shared_ptr<TScheduler> const& scheduler, TTag = DefaultTag{}) : scheduler{scheduler}
{
}

Expand Down
2 changes: 1 addition & 1 deletion redGrapes/redGrapes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ namespace redGrapes
}

template<typename T>
auto createIOResource(std::shared_ptr<T> o) -> IOResource<T>
auto createIOResource(std::shared_ptr<T> const& o) -> IOResource<T>
{
return IOResource<T>(o);
}
Expand Down
4 changes: 2 additions & 2 deletions redGrapes/resource/fieldresource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ namespace redGrapes
static constexpr size_t dim = trait::Field<Container>::dim;

FieldResource(Container* c)
: fieldresource::WriteGuard<Container>(TaskFreeCtx::create_resource_uid(), std::shared_ptr<Container>(c))
: fieldresource::WriteGuard<Container>(TaskFreeCtx::create_resource_uid(), std::make_shared<Container>(c))
{
}

Expand All @@ -304,7 +304,7 @@ namespace redGrapes

template<typename U>
FieldResource(FieldResource<U> const& res, Container* c)
: fieldresource::WriteGuard<Container>(res, std::shared_ptr<Container>(c))
: fieldresource::WriteGuard<Container>(res, std::make_shared<Container>(c))
{
}

Expand Down
8 changes: 4 additions & 4 deletions redGrapes/resource/resource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ namespace redGrapes
{
AccessBase(boost::typeindex::type_index access_type, std::shared_ptr<ResourceBase> resource)
: access_type(access_type)
, resource(resource)
, resource(std::move(resource))
{
}

Expand Down Expand Up @@ -116,7 +116,7 @@ namespace redGrapes
template<typename AccessPolicy>
struct Access : public AccessBase
{
Access(std::shared_ptr<ResourceBase> resource, AccessPolicy policy)
Access(std::shared_ptr<ResourceBase> const& resource, AccessPolicy policy)
: AccessBase(boost::typeindex::type_id<AccessPolicy>(), resource)
, policy(policy)
{
Expand Down Expand Up @@ -394,7 +394,7 @@ namespace redGrapes
template<typename T, typename AccessPolicy>
struct SharedResourceObject
{
SharedResourceObject(ResourceId id, std::shared_ptr<T> const& obj) : res{id}, obj(obj)
SharedResourceObject(ResourceId id, std::shared_ptr<T> obj) : res{id}, obj(std::move(obj))
{
}

Expand All @@ -405,7 +405,7 @@ namespace redGrapes
{
}

SharedResourceObject(Resource<AccessPolicy> const& res, std::shared_ptr<T> const& obj) : res{res}, obj{obj}
SharedResourceObject(Resource<AccessPolicy> const& res, std::shared_ptr<T> obj) : res{res}, obj{std::move(obj)}
{
}

Expand Down
2 changes: 1 addition & 1 deletion redGrapes/scheduler/thread_scheduler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace redGrapes
}

ThreadScheduler(std::shared_ptr<dispatch::thread::WorkerThread<Worker>> workerThread)
: m_worker_thread(workerThread)
: m_worker_thread(std::move(workerThread))
{
}

Expand Down
4 changes: 2 additions & 2 deletions redGrapes/util/atomic_list.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ namespace redGrapes
* and returns the previous head to which the new_head
* is now linked.
*/
auto append_item(std::shared_ptr<ItemControlBlock> new_head)
auto append_item(std::shared_ptr<ItemControlBlock> const& new_head)
{
TRACE_EVENT("Allocator", "AtomicList::append_item()");
std::shared_ptr<ItemControlBlock> old_head;
Expand All @@ -306,7 +306,7 @@ namespace redGrapes
}

// append the first head item if not already exists
bool try_append_first_item(std::shared_ptr<ItemControlBlock> new_head)
bool try_append_first_item(std::shared_ptr<ItemControlBlock> const& new_head)
{
TRACE_EVENT("Allocator", "AtomicList::append_first_item()");

Expand Down

0 comments on commit 2867117

Please sign in to comment.