On Monday, August 12, 2019 at 8:41:26 AM UTC-7, Emilio Cobos Álvarez wrote:
> If you don't use mozilla::Result, then you can stop reading now.
> 
> Result always returned the ok / errors by value. That's fine when the ok 
> or error values are cheap / small, like integers, but over time we've 
> been using Result<RefPtr<>> / Result<BigStruct> / Result<std::wstring>, etc.
> 
> Furthermore Result never worked with move-only types, so you couldn't 
> use Result<UniquePtr<>> or such.
> 
> In bug 1418624 I'm about to change mozilla::Result so that:
> 
>   * unwrap() / unwrapErr() / unwrapOr() / map() / andThen() move rather 
> than copy the result.
> 
>   * inspect() and inspectErr() return a reference to the ok / error 
> values respectively.
> 
> The first change allows the usage of move-only types, and is closer to 
> the Rust semantics (though C++ doesn't have the borrow-checker to 
> prevent use after moves).
> 
> The second change allows having big Result<>s on the stack, while not 
> paying extra stack space to inspect them.
> 
> I audited and changed all callers that were calling the now-moving 
> methods multiple times on the same error to use inspect() / 
> inspectErr(). Most of them shouldn't matter, as moving trivial types 
> doesn't do anything, but for some cases like some usages of std::wstring 
> it should have a positive impact on performance.
> 
> Let me know if there's any concerns with this or what not.
> 
> Cheers,
> 
>   -- Emilio

Neat! Thanks for doing this. It should allow for broader use of Result in media 
code.

Are there any footguns to watch out for when moving into the Result? Looking at 
the changes it appears that if my return type is Result<BigStruct> then I can 
just return a BigStruct? I.e. I don't need to do explicitly invoke anything 
else to avoid unintended copies.
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to