[
https://issues.apache.org/jira/browse/MESOS-1008?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Benjamin Mahler resolved MESOS-1008.
------------------------------------
Resolution: Fixed
Option patches committed:
{noformat}
commit 97ec42c5f25dfec24be2bdc61c5fa80624dc2d13
Author: Dominic Hamon <[email protected]>
Date: Thu Mar 13 23:00:20 2014 -0700
Changed Option::get to return a const reference to reduce copying.
Review: https://reviews.apache.org/r/18383
{noformat}
{noformat}
commit ed9f3f96e4b4f93a3413a06a7053dd6593ae18b3
Author: Dominic Hamon <[email protected]>
Date: Thu Mar 13 23:00:58 2014 -0700
Option::get reference cleanup in libprocess.
Review: https://reviews.apache.org/r/18384
{noformat}
{noformat}
commit e49fc2d7b7db65fa9921ba10b603f27378b1bdfa
Author: Dominic Hamon <[email protected]>
Date: Thu Mar 13 23:01:43 2014 -0700
Option::get reference cleanup in mesos.
Review: https://reviews.apache.org/r/18386
{noformat}
> Reduce copying in stout / libprocess primitives {Try, Option, Result, Future}.
> ------------------------------------------------------------------------------
>
> Key: MESOS-1008
> URL: https://issues.apache.org/jira/browse/MESOS-1008
> Project: Mesos
> Issue Type: Improvement
> Reporter: Benjamin Mahler
> Assignee: Dominic Hamon
>
> The following will discuss {{Try}}, but the same applies to {{Option}} and
> {{Result}}.
> Currently retrieving the value from a {{Try}} requires a copy:
> {code}
> T get() const { ... return *t; }
> {code}
> Instead, we can return a const&:
> {code}
> const T& get() const { ... return *t; }
> {code}
> For existing callers, this should be fairly seamless:
> {code}
> const T& t = try.get(); // No change needed.
> T t = try.get(); // No change needed, T is already required to be copyable.
> try.get().mutator(); // Will no longer compile, but we should not allow
> this anyway!
> {code}
> {code}
> const T& t = try.get();
> try = T(); // t is now garbage!
> t.foo(); // No longer works.
> {code}
> The last case is the most concerning as this mistake cannot be caught at
> compile-time. We could remove the assignment operators, but this seems overly
> restrictive. We could also guard (via {{CHECK}}) the assignment operator
> after a {{get()}} operation, but of course, we're also preventing valid
> {{Try}} usage if we go this route. The best path may simply be to leave the
> assignment operators as is (many callers already make copies).
> We can also add C++11 support for move to pilfer the {{Try}}, to avoid copies
> in the caller entirely:
> {code}
> T&& move() const { ... } // After a move(), we must guard Try operations.
> {code}
--
This message was sent by Atlassian JIRA
(v6.2#6252)