[
https://issues.apache.org/jira/browse/MESOS-1008?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13904926#comment-13904926
]
Benjamin Mahler commented on MESOS-1008:
----------------------------------------
The changes to Try have been committed:
{noformat}
commit 7bc99314403d63d2275e5da8c37c59e39b8f48f2
Author: Benjamin Mahler <[email protected]>
Date: Sun Feb 16 14:51:18 2014 -0800
Updated Try to return a const reference through get() to reduce unnecessary
copying.
Review: https://reviews.apache.org/r/18173
{noformat}
{noformat}
commit befe859f5d60c51177921287d1e959dd157533eb
Author: Benjamin Mahler <[email protected]>
Date: Sun Feb 16 14:52:20 2014 -0800
'Try' cleanups in libprocess, and other housekeeping.
Review: https://reviews.apache.org/r/18174
{noformat}
{noformat}
commit 829f23cc759d955dcb4836f7897865781475d925
Author: Benjamin Mahler <[email protected]>
Date: Sun Feb 16 14:52:40 2014 -0800
'Try' cleanups in mesos.
Review: https://reviews.apache.org/r/18175
{noformat}
Result, Option, and Future will follow.
> Reduce copying in stout primitives {Try, Option, Result}.
> ---------------------------------------------------------
>
> Key: MESOS-1008
> URL: https://issues.apache.org/jira/browse/MESOS-1008
> Project: Mesos
> Issue Type: Improvement
> Reporter: Benjamin Mahler
> Assignee: Benjamin Mahler
>
> The following will discuss Try, but the same applies to Option and Result.
> Currently retrieving the value from a Try requires a copy:
> T get() const { ... return *t; }
> Instead, we can return a const&:
> const T& get() const { ... return *t; }
> For existing callers, this should be fairly seamless:
> 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!
> const T& t = try.get();
> try = T(); // t is now garbage!
> t.foo(); // No longer works.
> 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:
> T&& move() const { ... } // After a move(), we must guard Try operations.
--
This message was sent by Atlassian JIRA
(v6.1.5#6160)